Pages

Monday, 7 March 2011

Sem 2 PHP Database

Employee database


//html code

<h2><center>INSERTION FOR DEPARTMENT TABLE</CENTER></h2>

<form action=employ1.php method=post>

<table border=0>

<tr>
<td><font size=5>Dept No</td>
<td><input type=text name=dno></td>
</tr>

<tr>
<td><font size=5>Dept name</td>
<td><input type=text name=dnm></td>
</tr>

<tr>
<td><font size=5>Location</td><td>
<input type=text name=loc></td>
</tr>

<tr>
<td><input type=submit value=insert></td>

<td><input type=reset value=reset></td>
</tr>

</table>

</form>



<H2><center>INSERTION FOR EMPLOYEE TABLE</CENTER></h2>

<form action=employ2.php method=post>
<table border=0>

<tr>
<td><font size=5>Dept No</td><td>
<input type=text name=dno></td>
</tr>

<tr><td><font size=5>Emp no</td>
<td><input type=text name=eno></td></tr>

<tr><td><font size=5>Emp name</td>
<td><input type=text name=enm></td></tr>

<tr><td><font size=5>Address</td>
<td><input type=text name=addr></td></tr>

<tr><td><font size=5>Phone no</td>
<td><input type=text name=phno></td></tr>

<tr><td><font size=5>Salary</td>
<td><input type=text name=sal></td></tr>

<tr><td><input type=submit value=insert></td>

<td><input type=reset value=reset></td></tr>

</table>
</form>


//php1.php

<?
 $dno=$_POST['dno'];
 $dnm=$_POST['dnm'];
 $loc=$_POST['loc'];
 $con=mysql_connect("localhost","root");
 if(!$con)
 echo"<h2>CONNECTION FAILED<br>";
 else
 echo"<h2>CONNECTION ESTABLISHED<br>";

 mysql_select_db("Sneha",$con);
 $res=mysql_query("insert into department values($dno,'$dnm','$loc')");
 if($res)
 echo"<h2>RECORD INSERTED SUCCESSFULLY<br>";
 else
 echo"<h2>RECORD NOT INSERTED<br>";
 mysql_close($con);
?>


//php2.php

<?
$eno=$_POST['eno'];
$enm=$_POST['enm'];
$addr=$_POST['addr'];
$phno=$_POST['phno'];
$sal=$_POST['sal'];
$dno=$_POST['dno'];
$con=mysql_connect("localhost","root");
mysql_select_db("Sneha",$con);
$res=mysql_query("select * from department where dno=$dno");
if($row=mysql_fetch_array($res))
{
$res1=mysql_query("insert into employee values($eno,'$enm','$addr',$phno,$sal,$dno)");
if($res1)
echo"<h2>INSERTION OF NEW EMPLOYEE IS DONE";
else
echo"<h1>INSERTION NOT DONE";
}
else
echo"<H1>RECORD NOT INSERTED DUE TO INVALID DEPARTMENT DNO</H1>";
mysql_connect($con);
?>


*****************************************************************************

mysql> select * from employee;
+-----+--------+----------+-----------+-------+------+
| eno | enm    | addr     | phno      | sal   | dno  |
+-----+--------+----------+-----------+-------+------+
|   1 | Raj    | Pune     |  27671378 | 15000 |    1 |

|   2 | Priya  | Talegoan |  27645678 | 16000 |    2 |
|   3 | Samrat | Mumbai   | 276456678 | 10000 |    1 |
|   4 | Gunjan | Rajkot   |   2745678 | 17000 |    2 |
|   5 | Mayank | Pimpri   |   2798765 | 27000 |    1 |
|   6 | Nupur  | Mumbai   |   2767689 | 23000 |    3 |
|   7 | Leela  | Dehuroad | 276768934 | 23500 |    3 |
+-----+--------+----------+-----------+-------+------+
7 rows in set (0.00 sec)

mysql> select * from department;
+-----+-------------+-----------+
| dno | dnm         | loc       |
+-----+-------------+-----------+
|   1 | Computer    | Bangalore |
|   2 | Electronics | Mumbai    |
|   3 | Maths       | Pune      |
+-----+-------------+-----------+
3 rows in set (0.00 sec)


//html code


<html>

<body>

<form action=employ3.php method=post>

<font size=5><b>Enter department name</b>
<input type=text name=dnm><br>

<input type=submit value=show>

<input type=reset value=reset>

</form>

</body>

</html>






//php code

<?
 $dnm=$_POST['dnm'];
 $con=mysql_connect("localhost","root");
 mysql_select_db("Sneha",$con);
 $res=mysql_query("select sal from employee,department where department.dno=employee.dno and dnm='$dnm'");
 $sum=0;
 $min=0;
 $max=0;
 while($row=mysql_fetch_array($res))
 {
  $cursal=$row['sal'];
  if($cursal>$max)
  $max=$cursal;
  else
  $min=$cursal;
  $sum=$min+$max;
 }
 echo"<H1>MAXIMUM AND MINIMUM SALARY OF ".$dnm." DEPARTMENT IS AS FOLLOWS</H1>";
 echo"<table border=2>";
 echo"<tr><td><b><font size=5>MAXIMUM SALARY</b></td><td><b><font size=5>MINIMUM SALARY</b></td><td><b><font size=5>SUM</b></td></tr>";
 echo"<tr><td><b><font size=5>$max</b></td><td><b><font size=5>$min</b></td><td><b><font size=5>$sum</b></td></tr>";
 echo"</table>";
?>
*******************************************************************************
HOSPITAL DOCTOR DATABASE :

Assignment No:-1          
Que No:2


************DOCTOR-HOSPITAL DATABASE*******************
mysql> select * from doctor;
+-----+---------------+------------------+-----------+
| dno | dnm           | addr             | city      |
+-----+---------------+------------------+-----------+
|   1 | AJIT KALE     | Shop no:22 Nigdi | Pune      |
|   2 | MAYANK SHARMA | Magadi road-24   | Bangalore |
|   3 | ANGAD MEHTA   | Garuda district  | Bhopal    |
|   4 | RAJA RAM      | Chakan road      | Chennai   |
+-----+---------------+------------------+-----------+






mysql> select * from DH;
+------+------+
| dno  | hno  |
+------+------+
|    1 |    1 |
|    2 |    3 |
|    3 |    2 |
|    4 |    1 |
|    3 |    3 |
|    1 |    3 |
+------+------+
6 rows in set (0.00 sec)

mysql> select * from hospital;
+-----+----------+-----------+
| hno | hnm      | city      |
+-----+----------+-----------+
|   1 | Lokmanya | Chinchwad |
|   2 | Sancheti | Kothrud   |
|   3 | Birla    | Pune      |
+-----+----------+-----------+
3 rows in set (0.00 sec)

//html file

<html>
<body>
<form action=dohos.php method=post>
<font size=5>
Enter Hospital Name<input type=text name=hnm><br>
<input type=submit value=submit>
<input type=reset value=reset>
</form>
</body>
</html>




//php file

<?
 $hnm=$_POST['hnm'];
 $con=mysql_connect("localhost","root");
 mysql_select_db("suhas",$con);
 $res=mysql_query("select doctor.dno,dnm,doctor.city,addr from doctor,hospital,DH where doctor.dno=DH.dno and hospital.hno=DH.hno and hnm='$hnm'");
 echo"<font size=5><i><center><b>Doctor Working/Visiting in ". $hnm." Hospital is</b></center></i><br>";
 echo"<table border=2 width=70%>";
 echo"<th><font size=5>DOCTOR NO</th><th><font size=5>DOCTOR NAME</th><th><font size=5>CITY</th><th><font size=5>ADDRESS</th>";
 while($row=mysql_fetch_array($res))
 {
  echo"<tr>";
  echo"<td align=center>"."<font size=6>".$row['dno']."</td>";
  echo"<td align=center>"."<font size=6>".$row['dnm']."</td>";
  echo"<td align=center>"."<font size=6>".$row['addr']."</td>";
  echo"<td align=center>"."<font size=6>".$row['city']."</td>";
  echo"</tr>";
 }
 echo"</table>";
 mysql_close($con);
?>
*******************************************************************************


MOVIE DATABASE:


mysql> create table movies(mno int primary key,mnm varchar(20),year varchar(20));
Query OK, 0 rows affected (0.09 sec).
mysql> select * from movies;
+-----+----------+------+
| mno | mnm      | year |
+-----+----------+------+
|   1 | dabang   | 2010 |
|   2 | 3 idiots | 2009 |
|   3 | Wanted   | 2009 |
|   4 | Veer     | 2010 |
|   5 | Ghajini  | 2008 |
+-----+----------+------+
5 rows in set (0.00 sec)

mysql> create table actor(ano int primary key,anm varchar(15),addr varchar(20));
Query OK, 0 rows affected (0.00 sec)
mysql> select * from actor;
+-----+-------------+-----------+
| ano | anm         | addr      |
+-----+-------------+-----------+
|   1 | Salman khan | mumbai    |
|   2 | Aamir khan  | Delhi     |
|   3 | Siddharth   | Bangalore |
+-----+-------------+-----------+
3 rows in set (0.00 sec)
mysql> create table MA(mno int references movies(mno),ano int references actor(ano),budget int);
Query OK, 0 rows affected (0.00 sec)
mysql> select * from MA;
+------+------+--------+
| mno  | ano  | budget |
+------+------+--------+
|    1 |    1 |  20000 |
|    2 |    2 | 230000 |
+------+------+--------+
2 rows in set (0.00 sec)


//HTML FILE
<html>
<body>
<form action=movie1.php method=post>
<font size=5>
Enter Actor Name<input type=text name=anm><br>
<input type=submit value=submit>
<input type=reset value=reset>
</form>
</body>
</html>

//PHP FILE

<?
 $anm=$_POST['anm'];
 $con=mysql_connect("localhost","root");
 mysql_select_db("manisha",$con);
 $res=mysql_query("select movies.mno,mnm,year from movies,actor,MA where movies.mno=MA.mno and actor.ano=MA.ano and anm='$anm'");
 echo"<font size=5><i><center><b>Actor ". $anm." acted in following MOVIES</b></center></i><br>";
 echo"<table border=2 width=70%>";
 echo"<th><font size=5>MOVIE NO</th><th><font size=5>MOVIE NAME</th><th><font size=5>RELEASE YEAR</th>";
 while($row=mysql_fetch_array($res))
 {
  echo"<tr>";
  echo"<td align=center>"."<font size=6>".$row['mno']."</td>";
  echo"<td align=center>"."<font size=6>".$row['mnm']."</td>";
  echo"<td align=center>"."<font size=6>".$row['year']."</td>";
  echo"</tr>";
 }
 echo"</table>";
 mysql_close($con);
?>
********************************************************************************

 //HTML SCRIPT
<form action=movie2.php method=post>
<font size=5>
<center><b>INSERTION FOR MOVIES TABLE</b></center>
<table border=0>
<tr><td><font size=5>MOVIE NO</td><td><input type=text name=mno></td></tr>
<tr><td><font size=5>MOVIE Name</td><td><input type=text name=mnm></td></tr>
<tr><td><font size=5>MOVIE Year</td><td><input type=text name=year></td></tr>
<tr><td><input type=submit value=submit></td><td><input type=reset value=reset></td></tr>
</table>
</form>

//PHP SCRIPT

<?
 $mno=$_POST['mno'];
 $mnm=$_POST['mnm'];
 $year=$_POST['year'];
 $con=mysql_connect("localhost","root");
 if(!$con)
 echo"<h2>CONNECTION FAILED<br>";
 else
 echo"<h2>CONNECTION ESTABLISHED<br>";

 mysql_select_db("Sneha",$con);
 $res=mysql_query("insert into movies values($mno,'$mnm','$year')");
 if($res)
 echo"<h2><I>RECORD INSERTED SUCCESSFULLY</I><br>";
 else
 echo"<h2>RECORD NOT INSERTED<br>";
 mysql_close($con);
?>


******** TO CHECK RECORD IS INSERTED OR NOT*************
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 5.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use Sneha;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

//AFTER INSERTION OF MNO=9

Database changed
mysql> select * from movies;
+-----+------------------+------+
| mno | mnm              | year |
+-----+------------------+------+
|   1 | dabang           | 2010 |
|   2 | 3 idiots         | 2009 |
|   3 | Wanted           | 2009 |
|   4 | Veer             | 2010 |
|   5 | Ghajini          | 2008 |
|   6 | Taare Zameen Par | 2008 |
|   7 |  Maan            | 2005 |
|   8 |  Mangal Pandey   | 2005 |
|   9 |  Bodyguard       | 2011 |  |
+-----+------------------+------+
10 rows in set (0.00 sec)

mysql>


****************************************************************************

<html>
<body>
<form action=movie3.php method=post>
<font size=5>
<center><b>TO UPDATE RELEASE YEAR</b></CENTER>
<table border=0>
<tr><td><font size=5>NEW RELEASE YEAR</td><td><input type=text name=year></td></tr>
<tr><td><font size=5>MOVIE NAME</td><td><input type=text name=mnm></td></tr>
<tr><td><font size><input type=submit value=submit></td><td><input type=reset value=reset></td></tr>
</form>
</html>
</body>

PHPcode:
<?
 $year=$_POST['year'];
 $mnm=$_POST['mnm'];
 $con=mysql_connect("localhost","root");
 if(!$con)
 echo"<h2>CONNECTION FAILED<br>";
 else
 echo"<h2>CONNECTION ESTABLISHED<br>";

 mysql_select_db("Sneha",$con);
 $res=mysql_query("update movies set year='$year' where mnm='$mnm'");
 if($res)
 echo"<h2>RECORD UPDATED SUCCESSFULLY<br>";
 else
 echo"<h2>RECORD NOT UPDATED<br>";
 mysql_close($con);
?>
*******************************************************************************
******************************************************************************

STUDENT COMPITITON :

Assignment No:-1
Que No:4


mysql> create table students(sno int primary key,snm varchar(20),class int);
Query OK, 0 rows affected (0.03 sec)
mysql> create table competetion(cno int primary key,cnm varchar(20),type varchar(20)); Query OK, 0 rows affected (0.00 sec)
mysql> create table SC(sno int references students(sno),cno int references competetion(cno),rank int);
Query OK, 0 rows affected (0.01 sec)
mysql> select * from student;
ERROR 1146 (42S02): Table 'Sneha.student' doesn't exist
mysql> select * from students;
+-----+----------+-------+
| sno | snm      | class |
+-----+----------+-------+
|   1 | Ram      |     3 |
|   2 | Suresh   |     6 |
|   3 | Sneha    |     9 |
|   4 | Nimisha  |     9 |
|   5 | Vijay    |     8 |
|   6 | Suprith  |     5 |
|   7 | Sonalish |     7 |
|   8 | Navin    |     6 |
+-----+----------+-------+
8 rows in set (0.00 sec)

mysql> select * from competetion;
+-----+------------+-------------------+
| cno | cnm        | type              |
+-----+------------+-------------------+
|   1 | High jump  | Sport             |
|   2 | Long jump  | Sport             |
|   3 | Quiz       | Academic          |
|   4 | Group Song | Cultural Activity |
+-----+------------+-------------------+
4 rows in set (0.00 sec)

mysql> select * from SC;
+------+------+------+
| sno  | cno  | rank |
+------+------+------+
|    1 |    1 |    2 |
|    2 |    5 |    1 |
|    3 |    1 |    1 |
|    4 |    3 |    1 |
|    5 |    2 |    1 |
|    6 |    4 |    2 |
|    7 |    4 |    1 |
|    8 |    3 |    2 |
+------+------+------+
8 rows in set (0.01 sec)

//html file

<html>
<body>
<form action=comstu.php method=post>
<font size=5>
Enter Competetion Name<input type=text name=cnm><br>
<input type=submit value=submit>
<input type=reset value=reset>
</form>
</body>
</html>


//php file
<?
 $cnm=$_POST['cnm'];
 $con=mysql_connect("localhost","root");
 mysql_select_db("Sneha",$con);
 $res=mysql_query("select students.sno,snm,class from students,competetion,SC where students.sno=SC.sno and competetion.cno=SC.cno and rank=1 and cnm='$cnm'");
 echo"<font size=5><i><center><b>Student came first in ". $cnm." competetion is</b></center></i><br>";
 echo"<table border=2 width=70%>";
 echo"<th><font size=5>STUDENT NUMBER</th><th><font size=5>STUDENT NAME</th><th><font size=5>CLASS</th>";
 while($row=mysql_fetch_array($res))
 {
  echo"<tr>";
  echo"<td align=center>"."<font size=6>".$row['sno']."</td>";
  echo"<td align=center>"."<font size=6>".$row['snm']."</td>";
  echo"<td align=center>"."<font size=6>".$row['class']."</td>";
  echo"</tr>";
 }
 echo"</table>";
 mysql_close($con);
?>











SEM 2 java networking

Server.java
import java.net.*;
import java.io.*;
import java.util.*;
class server
{
    public static void main(String a[])
    {
        try
        {
            ServerSocket sc=new ServerSocket(4200);
            System.out.println("waiting for connection");
            Socket s=sc.accept();
            OutputStream out=s.getOutputStream();
                DataOutputStream dout=new DataOutputStream(out);
            Date d= new Date();
            dout.writeUTF("Date "+d);
        }
        catch(Exception e)
        {
            System.out.println("Error "+e);
        }
    }
}

Client.java

import java.net.*;
import java.io.*;
class client1
{
    public static void main(String a[])
    {
        try{
            Socket sc=new Socket("localhost",4200);
            InputStream in=sc.getInputStream();
            DataInputStream din=new DataInputStream(in);
            String s=din.readUTF();
            System.out.println("Date of Server " +s);
        }catch(Exception e)
        {
            System.out.println("Error"+e);
        }
    }
}
*****************************************************************************
server

import java.io.*;
import java.util.*;
import java.net.*;
class seta2serv
{
    public static void main(String a[])
    {
        try
        {
            ServerSocket sc=new ServerSocket(4200);
            System.out.println("waiting for connection");
            Socket s=sc.accept();
            System.out.println("connection is established");
            InputStream in=s.getInputStream();
            DataInputStream din= new DataInputStream(in);
            String name=din.readUTF();
            System.out.println("File Name"    +name);
            OutputStream out=s.getOutputStream();
            DataOutputStream dout=new DataOutputStream(out);
            File f1=new File(name);
            if(f1.exists())
            {
                String msg="",str="";
                FileReader fr=new FileReader(name);
                BufferedReader br=new BufferedReader(fr);
                while((str=br.readLine())!=null)
                    msg=msg+str+"\n";
                dout.writeUTF("CONTENTS OF FILE:-\n"+msg);
            }
            else
                dout.writeUTF("0");
        }
        catch(Exception e)
        {
            System.out.println("Error="+e);
        }
    }
}

Client :

import java.io.*;
import java.net.*;


class seta2clin
{
public static void main(String a[])
{

try
{
           Socket s=new Socket("localhost",4200);
           BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the file name is");
String name=br.readLine();

OutputStream out=s.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
dout.writeUTF(name);
InputStream in=s.getInputStream();
DataInputStream din=new DataInputStream(in);
String msg=din.readUTF();
if(msg.equals("0"))
System.out.println("file not found");
else
System.out.println(msg);


}
catch(Exception e)
{
System.out.println("Error is:"+e);

}
}
}
*********************************************************************

server.java b1

import java.io.*;
import java.net.*;
class setb1serv
{
    public static void main(String a[])
    {
        try
        {
            ServerSocket sc=new ServerSocket(4200);
            System.out.println("Waiting for connection");
            Socket s=sc.accept();
            System.out.println("connection is establish");
            InputStream in=s.getInputStream();
            DataInputStream din=new DataInputStream(in);
            OutputStream out=s.getOutputStream();
            DataOutputStream dout= new DataOutputStream(out);
            for(int i=0;i<3;i++)
            {
                String name=din.readUTF();
                System.out.println("name of File"   +name);
                File f1=new File(name);
                if(f1.exists())
                {
                    dout.writeUTF("1");
                }
                else

                    dout.writeUTF("0");
            }
}
            catch(Exception e)
            {
                System.out.println("Error" +e);
            }
        }
    }

Client












import java.io.*;
import java.net.*;
class setb1clin
{
    public static void main(String a[])
    {
           try
               {
        Socket s=new Socket("localhost",4200);
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        InputStream in=s.getInputStream();
        DataInputStream din=new DataInputStream(in);
        OutputStream out=s.getOutputStream();
        DataOutputStream dout=new DataOutputStream(out);
        System.out.println("enter no of file to Check");
        int n=Integer.parseInt(br.readLine());
        int  cnt=0,i;
        for(i=0;i<4;i++)
        {
            System.out.println("enter the File Name");
                        String name=br.readLine();
            dout.writeUTF(name);
            String msg=din.readUTF();
            if(msg.equals("0"))
                System.out.println("file is not exists");
            else
            {
                cnt=cnt+1;
                System.out.println("file exists");
            }
        }
        System.out.println("total number of File:"+cnt);
    }
    catch(Exception e)
    {
        System.out.println("error" +e);
    }
}
}


******************************************************************************
server

import java.io.*;
import java.net.*;
class setb2clin
{
    public static void main(String a[])
    {
        try
        {
            Socket s=new Socket("localhost",4200);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            OutputStream out=s.getOutputStream();
                DataOutputStream dout=new DataOutputStream(out);
            InputStream in=s.getInputStream();

                DataInputStream din=new DataInputStream(in);
            while(true)
            {
                System.out.println("enter the String");
                String s1=br.readLine();
                                try{

                if(s1.equals("Bye"))
                {
                    dout.writeUTF(s1);
                    String msg=din.readUTF();
                    System.out.println("msg from Server is"+msg);
                }
                           
                             } catch(Exception e){}
                        }
                   }catch(Exception e)
                {

                    System.out.println("Error"+e);
                }
           
         }
}

Client

import java.io.*;
import java.net.*;
class setb2clin
{
    public static void main(String a[])
    {
        try
        {
            Socket s=new Socket("localhost",4200);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            OutputStream out=s.getOutputStream();
                DataOutputStream dout=new DataOutputStream(out);
            InputStream in=s.getInputStream();

                DataInputStream din=new DataInputStream(in);
            while(true)
            {
                System.out.println("enter the String");
                String s1=br.readLine();
                                try{

                if(s1.equals("Bye"))
                {
                    dout.writeUTF(s1);
                    String msg=din.readUTF();
                    System.out.println("msg from Server is"+msg);
                }
                           
                             } catch(Exception e){}
                        }
                   }catch(Exception e)
                {

                    System.out.println("Error"+e);
                }
           
         }
}

*******************************************************************************







SEM 2 java Graphics

import java.awt.*;
import javax.swing.*;
class seta1 extends JFrame
{
      seta1()
        {
            setVisible (true);
             setSize(500,500);
             setTitle("Hellow World");
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
       public void paint(Graphics g)
        {
              g.setFont(new Font("Arial",Font.BOLD,40));
              g.drawString("Hellow 2d Graphics",20,70);
              g.setFont(new Font("Times new romen",Font.ITALIC,50));
              g.drawString("Hellow 2d Graphics",20,200);
              g.setFont(new Font("Hellow 2d Graphics",Font.PLAIN,50));
              g.drawString("Hellow 2d Graphics",20,350);         
        }
         public static void main(String a[])
            {
                 new seta1();
            }
}
*********************************************************************************
import java.awt.*;
import javax.swing.*;
class seta2 extends JFrame
{
      seta2()
        {
            setVisible (true);
             setSize(500,500);
             setTitle("MachinFont and Matrics");
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
       public void paint(Graphics g)
        {
             GraphicsEnvironment g1=GraphicsEnvironment.getLocalGraphicsEnvironment();
             String s[]=g1.getAvailableFontFamilyNames();
               FontMetrics fm=g.getFontMetrics();
                   int x=fm.getHeight();
                   Font f=fm.getFont();
             
              g.drawString("Hieght=,"+x+"Font="+f.getFontName(),30,60);
                    int y=70;
              for(int i=0;i<s.length;i++)

                  {
                     g.drawString(s[i],20,y);
                     y=y+15;
                  }
           }
           public static void main(String a[])
                  {
                     new seta2();
                   }
 }
*********************************************************************************

import java.awt.*;
import javax.swing.*;
class seta3 extends JFrame
{
    seta3()
    {
        setVisible (true);
        setSize(600,600);
        setTitle("Information of fonts");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void paint(Graphics g)
    {
        Font f=g.getFont();
        g.setFont(new Font("Arial",Font.PLAIN,20));
                 g.drawString("font name="+f.getFontName(),30,50);

        g.drawString("font size="+f.getSize(),20,70);
        g.drawString("font Family="+f.getFamily(),20,90);
        g.drawString("font style="+f.getStyle(),20,120);
        g.drawString("font logic name="+f.getName(),20,150);
    }
    public static void main(String a[])
    {
        new seta3();
    }
}
*******************************************************************************


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;

 class seta4 extends JFrame implements ActionListener
          {
             JPanel p=new JPanel();
             JButton b=new JButton("open");
             Image img;
             int a=1;
            
             seta4()
              {
                 setLayout(new FlowLayout());
                 add(b);
                 add(p);
                 b.addActionListener(this);
                 setVisible(true);
                 setTitle("Image");
                 setSize(500,500);
                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              }
              public void actionPerformed(ActionEvent e)
              {
                try
                 {
                   FileDialog f=new FileDialog(this,"open");
                   f.setVisible(true);
                   System.out.println("name="+f.getDirectory()+""+f.getFile());
                  img=ImageIO.read(new File(f.getDirectory()+f.getFile()));
                   repaint();
                 }
                 catch(Exception e1)
                     {
                        System.out.println("error="+e1);
                     }
               }
               public void paint(Graphics g)
                     {
                      if(a==1);
                       g.drawImage(img,20,20,null); 
                     }


               public static void main(String a[])
               {
                   new seta4();
               }
}
*******************************************************************************


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class setb11 extends JFrame
{
public setb11()
{
super("polygon Draw");
setSize(425,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);

}
public void paint(Graphics comp)
{
Graphics2D comp2D=(Graphics2D)comp;
GeneralPath poly=new GeneralPath();
poly.moveTo(70f,25f);
poly.lineTo(140f,90f);
poly.lineTo(140f,200f);
poly.lineTo(90f,200f);
poly.lineTo(90f,150f);                                                          poly.lineTo(50f,150f);
poly.lineTo(50f,200f);     
poly.lineTo(5f,200f);
poly.lineTo(5f,90f);           
poly.closePath();
comp2D.draw(poly);
Line2D line1=new Line2D.Float(5f,90f,140f,90f);
Line2D line2=new Line2D.Float(50f,200f,90f,200f);
comp2D.draw(line1);
comp2D.draw(line2);
Ellipse2D ellipse=new Ellipse2D.Float(60f,50f,25f,25f);

comp2D.draw(ellipse);

}
public static void main(String a[])
{
new setb11();

}
}

************************************************************************



import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class setb2 extends JFrame
{
public setb2()
{
super("polygon Draw");
setSize(425,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);

}
public void paint(Graphics comp)
{
Graphics2D comp2D=(Graphics2D)comp;
GeneralPath poly=new GeneralPath();
poly.moveTo(25f,90f);
poly.lineTo(60f,90f);
poly.lineTo(60f,130f);
poly.lineTo(120f,130f);
poly.lineTo(120f,170f);
poly.lineTo(25f,170f);
poly.closePath();
comp2D.draw(poly);
Line2D line1=new Line2D.Float(25f,130f,60f,130f);
comp2D.draw(line1);
Ellipse2D ellipse=new Ellipse2D.Float(30f,170f,25f,25f);
Ellipse2D ellipse1=new Ellipse2D.Float(90f,170f,25f,25f);
comp2D.draw(ellipse);
comp2D.draw(ellipse1);
}
public static void main(String a[])
{
new setb2();

}
}



***********************************************************************8










SEM 2 java ass 4 Collection

Collection
/*
 2. Construct a linked List containing names of colors: red, blue, yellow and orange.
      Then extend your program to do the following:
      i.     Display the contents of the List using an Iterator;
      ii.    Display the contents of the List in reverse order using a ListIterator;
      iii. Create another list containing pink and green. Insert the elements of this list
             between blue and yellow.
 */
import java.util.*;
public class collection1
{

    public static void main(String[] args)
    {
    LinkedList t=new LinkedList();
    t.add("red");
    t.add("blue");
    t.add("yellow");
    t.add("orange");
    Iterator i=t.iterator();
    System.out.println("The Elements Are");
    while(i.hasNext())
    System.out.println(i.next());
    ListIterator i1=t.listIterator();
    while(i1.hasNext())
    i1.next();
    System.out.println("The Elements In Reverse Order");
    while(i1.hasPrevious())
    System.out.println(i1.previous());
    LinkedList t2=new LinkedList();
    t2.add("pink");
    t2.add("green");
    i=t2.iterator();
    t.add(2, i.next());
    t.add(3, i.next());
    Iterator i2=t.iterator();
    System.out.println("The Total Elements Are");
    while(i2.hasNext())
    System.out.println(i2.next());
  }
}
***************************************************************************

/*
Assignment no :4 seta2

2. Create a Hash table containing student name and percentage. Display the details of

the hash table. Also search for a specific student and display percentage of that student.

*/
import java.util.*;

import java.io.*;

import java.util.Map.Entry;

public class a2

{

    public static void main(String[] args) throws IOException

    {

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    Hashtable hm=new Hashtable();

    hm.put("Ganesh",new Double(74.89));

    hm.put("Ramesh",new Double(64.89));

    hm.put("Ram",new Double(55.89));

    hm.put("Mahesh",new Double(84.89));

    Set s=hm.entrySet();

    Iterator i=s.iterator();

    System.out.println("Name     Percentage");

    while(i.hasNext())

   {

        Map.Entry me=(Entry) i.next();

        System.out.println(""+me.getKey()+"     "+me.getValue());   

    }

    System.out.println("Enter the student name for search");

    String nm=br.readLine();

    Iterator i1=s.iterator();

    while(i1.hasNext())

    {

        Map.Entry me=(Entry) i1.next();

        if(nm.equalsIgnoreCase((String) me.getKey()))

        System.out.println("The percentage are:"+me.getValue());

    }

   }

}
/*
output:

Name     Percentage

Ganesh     74.89

Mahesh     84.89

Ramesh     64.89

Ram     55.89

Enter the student name for search

ganesh

The percentage are:74.89



*/
**********************************************************************************

/*

  1. Accept n integers from the user and store them in a collection. Display them in the

sorted order. The collection should not accept duplicate elements. (Use a suitable

collection).

 */

import java.util.*;

import java.io.*;

public class a3

{

    public static void main(String[] args) throws IOException

    {

    int n;

    TreeSet t=new TreeSet();

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Enter the no of elements");

    n=Integer.parseInt(br.readLine());

    Integer[] no=new Integer[n];

    System.out.println("Enter the no");

    for(int i=0;i<n;i++)

    {

    int a;

    a=Integer.parseInt(br.readLine());

    no[i]=new Integer(a);

    t.add(no[i]);

    }

    Iterator it=t.iterator();

    System.out.println("The Sorted data");

    while(it.hasNext())

    System.out.println(it.next());

  }

}
********************************************************************************




/*implement Hash table to store n records of students ( Name, Percentage). Write a

menu driven program to :

             1. Add student

             2. Display details of all students

             3. Search student

             4. Find out highest marks

 */

import java.util.*;

import java.io.*;

import java.util.Map.Entry;



class democomp implements Comparator

{

public int compare(Object o,Object o1)

{

Double a,b;

a=(Double)o;

b=(Double)o1;

return b.compareTo(a);

}

}



public class b1

{

    public static void main(String[] args) throws IOException

    {

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    int n,cont;

    String nm;

    Double db;

    double d;

    HashMap hm=new HashMap();

    System.out.println("Enter the no of student");

    n=Integer.parseInt(br.readLine());

    for(int i=0;i<n;i++)

    {

    System.out.println("Enter the name");

    nm=br.readLine();

    System.out.println("Enter the percentage");

    d=Double.parseDouble(br.readLine());

    db=new Double(d);

    hm.put(nm,db);

    }

    do

    {

    System.out.println(" 1.Add Student \n 2.Display details of all students \n 3.Search result \n 4.Search highest marks");

    System.out.println("Enter the choice");

    int ch=Integer.parseInt(br.readLine());

    Set s=hm.entrySet();

    switch(ch)

    {

        case 1:

            System.out.println("Enter the name");

            nm=br.readLine();

            System.out.println("Enter the percentage");

            d=Double.parseDouble(br.readLine());

            db=new Double(d);

            hm.put(nm,db);

            break;

        case 2:

            Iterator i=s.iterator();

            System.out.println("Name     Percentage");

            while(i.hasNext())

             {

                Map.Entry me=(Entry) i.next();

                System.out.println(""+me.getKey()+"     "+me.getValue());

             }

            break;

        case 3:

             System.out.println("Enter the student name for search");

             nm=br.readLine();

             Iterator i1=s.iterator();

             while(i1.hasNext())

             {

                Map.Entry me=(Entry) i1.next();

                if(nm.equalsIgnoreCase((String) me.getKey()))

                System.out.println("The percentage are:"+me.getValue());

             }

             break;

        case 4:

         democomp dc=new democomp();

             TreeSet t=new TreeSet(dc);

             Iterator i2=s.iterator();

             while(i2.hasNext())

             {

                Map.Entry me=(Entry) i2.next();

                t.add(me.getValue());

             }

             i2=t.iterator();

             Double d5=(Double) i2.next();

             i2=s.iterator();

             while(i2.hasNext())

             {

                Map.Entry me=(Entry) i2.next();

                if(d5.equals(me.getValue()))

                System.out.println("Name is:"+me.getKey()+"\nThe percentage are:"+me.getValue());

             }

             break;

         }

      System.out.println("Do you want continue press 1");

      cont=Integer.parseInt(br.readLine());

      }while(cont==1);

    }

   }

*********************************************************************************








/*

list). Perform

            a. Union

            b. Intersection

            c. Combining corresponding elements of the lists into a new list (only if they

               are of the same size)

*/

import java.io.*;

import java.util.*;

public class b2

{

    public static void main(String[] args) throws IOException

    {

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    int cont;

    TreeSet t=new TreeSet();

    t.add("ganesh");

    t.add("ramesh");

    t.add("ram");

    t.add("mayur");

    LinkedList l=new LinkedList(t);

    TreeSet t1=new TreeSet();

    t1.add("ganesh");

    t1.add("mayur");

    t1.add("ram");

    t1.add("aditya");

    LinkedList l1=new LinkedList(t1);

    do

    {

    System.out.println(" 1.Union \n 2.Intersection \n 3.Combining the list");

    System.out.println("Enter the choice");

    int ch=Integer.parseInt(br.readLine());

    switch(ch)

    {

        case 1:

            TreeSet t2=new TreeSet();

            Iterator i=l.iterator();

            while(i.hasNext())

            t2.add(i.next());

            i=l1.iterator();

            while(i.hasNext())

            t2.add(i.next());

            LinkedList l2=new LinkedList(t2);

            System.out.println("The Union of list\n"+l2);

            break;

        case 2:

            int ic=0,ic1=0;

            LinkedList l3=new LinkedList();

            i=l1.iterator();

            String[] nm=new String[10];

            while(i.hasNext())

            {

                nm[ic]=(String) i.next();

                ic++;

            }

            i=l.iterator();

            String[] nm1=new String[10];

            while(i.hasNext())

            {

                nm1[ic1]=(String) i.next();

                ic1++;

            }

            for(int k=0;k<ic;k++)

            {

                for(int s=0;s<ic1;s++)

                {

                    if(nm[k].equals(nm1[s]))

                    l3.add(nm[k]);

                }

            }

            System.out.println("The intersection of list\n"+l3);

            break;

        case 3:

            if(l.size()==l1.size())

            {

            int ic2=0,ic3=0;

            LinkedList l5=new LinkedList();

            i=l1.iterator();

            String[] nm2=new String[10];

            while(i.hasNext())

            {

                nm2[ic2]=(String) i.next();

                ic2++;

            }

            i=l.iterator();

            String[] nm3=new String[10];

            while(i.hasNext())

            {

                nm3[ic3]=(String) i.next();

                ic3++;

            }

            String comb[]=new String[ic2];

            for(int k=0;k<ic2;k++)

            {

               comb[k]=""+nm2[k]+" "+nm3[k];

               l5.add(comb[k]);

            }

            System.out.println("The combination of two list\n"+l5);

            }

           else

                System.out.println("The size of linked list are not same");

            break;

      }

      System.out.println("Do you want continue press 1");

      cont=Integer.parseInt(br.readLine());

  }while(cont==1);

 }



}
****************************************************************************





/*Read a text file, specified by the first command line argument, into a list. The
  program should then display a menu which performs the following operations on the list:
  1. Insert line 2. Delete line 3. Append line 4. Modify line 5. Exit
  When the user selects Exit, save the contents of the list to the file and end the program.
 */
import java.io.*;
import java.util.*;

public class c1
{
    public static void main(String[] args)throws Exception
    {
        try
        {
            String filename=args[0];
            String line;
            BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
            LinkedList l=new LinkedList();
            FileReader f=new FileReader(filename);
            BufferedReader br=new BufferedReader(f);
            do
            {
                line=br.readLine();
                if(line==null)
                    break;
                l.add(line);
            }while(true);
            br.close();
            do
            {
                System.out.println(" 1.Insert line \n 2.Delete line \n 3.Append line \n 4.Modify line \n 5.Exit");
                System.out.println("Enter the choice");
                int ch=Integer.parseInt(br1.readLine());
                switch(ch)
                {
                    case 1:
                        System.out.println("Enter the po");
                        int po=Integer.parseInt(br1.readLine());
                        System.out.println("Enter the line");
                        String line1=br1.readLine();
                        l.add(po-1, line1);
                        break;
                    case 2:
                        System.out.println("Enter the po");
                        int po1=Integer.parseInt(br1.readLine());
                        l.remove(po1-1);
                        break;
                    case 3:

                                                System.out.println("Enter the po");
                                                int po2=Integer.parseInt(br1.readLine());
            
                        System.out.println("Enter the line");
                        String line2=br1.readLine();
                        l.add(po2, line2);
                        break;
                    case 4:
                        System.out.println("Enter the po");
                        int po3=Integer.parseInt(br1.readLine());
                        System.out.println("Enter the line");
                        String line3=br1.readLine();
                        l.set(po3-1, line3);
                        break;
                    case 5:
                        FileWriter fw=new FileWriter(filename);
                        PrintWriter pr=new PrintWriter(fw);
                        ListIterator li=l.listIterator();
                        while(li.hasNext())
                        {
                            pr.println(li.next());
                        }
                        pr.close();
                        System.exit(0);
                        break;
                }
            }while(true);
                   
        }catch(Exception e){}
}
   
}




SEM1 java ass 8 applet


****************************Que.:Ass:8 set:A Q.1*****************************

Que)Create an applet to display a message at the center of the applet. The message is
passed as a parameter to the applet.

**********************************Java Code**********************************
import java.applet.*;
import java.awt.*;

/*
<applet code = "seta1.class" width = 400 height = 400 align = "middle">
<param name = "FontName" value = "yellow" >
<param name = "Message" value = "This is my first applet program" >
</applet>
 */

public class seta1 extends Applet
{
        String msg;

        public void init()
        {
       
                msg = getParameter("Message");
        }

        public void paint(Graphics g)
        {
                g.drawString(msg, 80,50);
        }
}
*****************************************************************************


****************************Que.:Ass:8 set:A Q.2*****************************
Que)Create an applet to display coordinates of mouse movements in a text box.

********************************Java Code************************************

import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet CODE="seta2.class" width=500 height=350>
</applet>
*/

public class seta2 extends Applet
{
        JTextField t1;
        public void init()
        {
                t1=new JTextField(10);
                add(t1);
                addMouseMotionListener(new MouseMotionAdapter()
                {
                        public void mouseMoved(MouseEvent me)
                        {
                                t1.setText("X: "+me.getX()+"Y: "+me.getY());
                        }
                });
        }
}

****************************************************************************


****************************Que.:Ass:8 set:A Q.3************************   
Que)Create a conversion applet which accepts value in one unit and converts it to another.
The input and output unit is selected from a list. Perform conversion to and from Feet,
Inches, Centimeters, Meters and Kilometers.
*************************************Java Code***************************
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.applet.*;

/*
   <applet CODE="seta3.class" width=550 height=200>
   </applet>
 */

public class seta3 extends Applet implements ItemListener
{
        JLabel l1,l2,l3,l4;
        JTextField t1,t2;
        JComboBox c1,c2;
        String s1[];
        JPanel p1,p2;
        public void init()
        {
                l1=new JLabel("Input");
                l2=new JLabel("Output");
                l3=new JLabel("Unit");
                l4=new JLabel("Unit");
                s1=new String[]{"Feets","Centimeters","Inches","Meters","Kilometers"};
                c1=new JComboBox(s1);
                c2=new JComboBox(s1);
                c1.addItemListener(this);
                c2.addItemListener(this);
                t1=new JTextField(10);
                t2=new JTextField(10);
                p1=new JPanel();
                p2=new JPanel();
                p1.setLayout(new GridLayout(1,4));
                p1.add(l1);
                p1.add(t1);
                p1.add(l2);
                p1.add(t2);
                p2.setLayout(new GridLayout(1,4));
                p2.add(l3);
                p2.add(c1);
                p2.add(l4);
                p2.add(c2);
                setLayout(new GridLayout(2,1));
                add(p1);
                add(p2);

        }
        public void itemStateChanged(ItemEvent ie)
        {
                Double ip,op;
                String s1=(String)c1.getSelectedItem();
                String s2=(String)c2.getSelectedItem();
                if(s1.equals("Feets"))
                {
                        ip=Double.parseDouble(t1.getText());
                        if(s2.equals("Inches"))
                        {       op=12*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Centimeters"))
                        {       op=12*2.5*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Meters"))
                        {       op=((12*2.5)/100)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Kilometers"))
                        {       op=((12*2.5)/1000)*ip;
                                t2.setText(op.toString());
                        }

                }
                if(s1.equals("Inches"))
                {
                        ip=Double.parseDouble(t1.getText());
                        if(s2.equals("Feets"))
                        {       op=(1/12)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Centimeters"))
                        {       op=(1/2.5)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Meters"))
                        {       op=(1/2.5/100)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Kilometers"))
                        {       op=(1/2.5/100/1000)*ip;
                                t2.setText(op.toString());
                        }

                }
                if(s1.equals("Kilometers"))
                {
                        ip=Double.parseDouble(t1.getText());
                        if(s2.equals("Meters"))
                        {       op=1000*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Centimeters"))
                        {       op=100*1000*ip;
                                t2.setText(op.toString());
                        }

                        if(s2.equals("Feets"))
                        {       op=1000*100*ip*30;
                                t2.setText(op.toString());
                        }

                        if(s2.equals("Inches"))
                        {       op=(1000*100*ip*30)/100;
                                t2.setText(op.toString());
                        }


                }
                if(s1.equals("Meters"))
                {
                        ip=Double.parseDouble(t1.getText());
                        if(s2.equals("Centimeters"))
                        {       op=100*ip;
                                t2.setText(op.toString());
                        }
                        else if(s2.equals("Kilometers"))
                        {       op=0.001*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Feets"))
                        {       op=(100*ip)*30;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Inches"))
                        {       op=(100*ip)/2.5;
                                t2.setText(op.toString());
                        }

                }
                if(s1.equals("Centimeters"))
                {
                        ip=Double.parseDouble(t1.getText());
                        if(s2.equals("Meters"))
                        {       op=0.01*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Inches"))
                        {       op=(1/2.5)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Kilometers"))
                        {       op=(0.01/1000)*ip;
                                t2.setText(op.toString());
                        }
                        if(s2.equals("Feets"))
                        {       op=(1/2.5/12)*ip;
                                t2.setText(op.toString());
                        }
                }
        }
}

******************************************************************************

***************************Que.:Ass:8 set:B Q.1************************
Que)Create an Applet which displays a message in the center of the screen. The message
indicates the events taking place on the applet window. Handle events like mouse click,
mouse moved, mouse dragged, mouse pressed, and key pressed. The message should
update each time an event occurs. The message should give details of the event such as
which mouse button was pressed, which key is pressed etc. (Hint: Use repaint(),
KeyListener, MouseListener, MouseEvent method getButton, KeyEvent methods
getKeyChar)
*****************************Java Code**********************************
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
<applet code="setb1.class" width=200 height=200>
</applet>
*/

public class setb1 extends Applet implements MouseMotionListener, MouseListener, KeyListener
{
        String s="";
        public void init()
        {
        addMouseListener(this);
        addKeyListener(this);
        addMouseMotionListener(this);
        }


         public void keyTyped(KeyEvent ke)
        {
        char c;
        c=ke.getKeyChar();
         s="Key is Typed"+""+c;
        repaint();
        }
         public void keyPressed(KeyEvent ke)
        {
        char c;
         c=ke.getKeyChar();
          s="Key is Pressed"+""+c;
         repaint();
        }
         public void keyReleased(KeyEvent ke)
        {
        char c;
        c=ke.getKeyChar();
        s="Key is Released"+""+c;
         repaint();
        }


        public void mouseClicked(MouseEvent me)
        {
         if(me.getButton()==MouseEvent.BUTTON3)
        {
        s="Right Button is clicked";
        }
         if(me.getButton()==MouseEvent.BUTTON2)
        {
        s="Centre Button is clicked";
        }
 if(me.getButton()==MouseEvent.BUTTON1)
        {
        s="Left Button is clicked";
        }

         repaint();
        }
        public void mousePressed(MouseEvent me)
        {
        if(me.getButton()==MouseEvent.BUTTON3)
        {
        s="Right Button is pressed";
        }
         if(me.getButton()==MouseEvent.BUTTON2)
        {
        s="Centre Button is pressed";
        }
 if(me.getButton()==MouseEvent.BUTTON1)
        {
        s="Left Button is pressed";
        }
         repaint();
        }
        public void mouseReleased(MouseEvent me)
        {
         s="Mouse Button is released";
         repaint();
        }
        public void mouseEntered(MouseEvent me)
        {
         s="Mouse Button is entered";
         repaint();
        }
         public void mouseExited(MouseEvent me)
        {
         s="Mouse Button is exited";
         repaint();
        }
        public void mouseDragged(MouseEvent me)
        {
        int x=me.getX();
        int y=me.getY();

         s="The is Dragged at "+"X axis="+x+""+"Y axis="+y;
        repaint();
        }
        public void mouseMoved(MouseEvent me)
        {
         int x=me.getX();
        int y=me.getY();
        s="The is moved at"+"X axis="+x+""+"Y axis="+y;
        repaint();
        }
        public void paint(Graphics g)
        {
        g.drawString(s,100,100);
        }
}//end of class

*****************************************************************************


***************************Que.:Ass:8 set:B Q.2******************************
Que)Create an applet which allows the user to draw figures like Oval, Line, Rectangle and
Rounded Rectangle. The selection is done using radio buttons. Retain previous drawn
objects on the applet window. (Hint: use update() method )

********************************Java Code************************************

import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet code="setb2.class" width=500 height=400 align=left/>
</applet>
*/

public class setb2 extends Applet implements ActionListener
{

        JRadioButton bLine,bCircle,bRect,bRRect;
        ButtonGroup g1;
        Point start,end;
        boolean line=false, circle=false,rect=false,rrect=false;
        public void init()
        {
        g1=new ButtonGroup();
        bLine=new JRadioButton("Line");
        bCircle=new JRadioButton("Circle");
        bRect=new JRadioButton("Rectangle");
        bRRect=new JRadioButton("Round Rect");
        g1.add(bLine);
        g1.add(bCircle);
        g1.add(bRect);
        g1.add(bRRect);
        add(bLine);
        add(bCircle);
        add(bRect);
        add(bRRect);
        bLine.addActionListener(this);
        bCircle.addActionListener(this);
        bRect.addActionListener(this);
        bRRect.addActionListener(this);

        addMouseListener(new MouseAdapter()
        {
        public void mousePressed(MouseEvent e)
        {
        start=new Point(e.getX(),e.getY());
        }
        public void mouseReleased(MouseEvent e)
        {
        end=new Point(e.getX(),e.getY());
        repaint();
        }
        });
        }


        public void  actionPerformed(ActionEvent ae)
        {
        resetFlags();
        JRadioButton b=(JRadioButton)ae.getSource();
        if(b==bLine) line=true;
         if(b==bCircle) circle=true;
         if(b==bRect) rect=true;
         if(b==bRRect) rrect=true;

        }

        void resetFlags()
        {
        line=false;
         circle=false;
         rect=false;
         rrect=false;
        }

        public void paint(Graphics g)
        {
        if(line)
        g.drawLine(start.x,start.y,end.x,end.y);
        else
        if(circle)
        g.drawOval(start.x,start.y,end.x-start.x,end.y-start.y);
        if(rect)
         g.drawRect(start.x,start.y,end.x-start.x,end.y-start.y);
        if(rrect)
         g.drawRoundRect(start.x,start.y,end.x,start.x,end.y,start.y);
        update(g);
        }

        public void update(Graphics g)
        {
        paint(g);
        }
}
*****************************************************************************