/***************************************************************************/
NAME :: ROLL NO ::
Practical Name :: Write a java program to accept n names of cites from user and display
them in descending order.
Practical no. ::01
Date :: Remark ::
/***************************************************************************/
Practical no. ::01
Date :: Remark ::
/***************************************************************************/
import java.io.*;
class CityDemo
{
public static void main(String args[])
{
String city[]=new String[5];
int i,j;
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(i=0;i<5;i++)
{
System.out.println("Enter the "+(i+1)+" city");
city[i]=br.readLine();
}
System.out.println("-*-*-*-*-*-*-*-Descending order of cities-*-*-*-*-*-*-*-*");
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if((city[i].compareTo(city[j]))>0)
{
String temp=city[i];
city[i]=city[j];
city[j]=temp;
}
}
}
for(i=4;i>=0;i--)
{
System.out.println(city[i]);
}
System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
}
catch(Exception e)
{ }
}
}
OutPut:-
Enter the 1 city
Pune
Enter the 2 city
Mumbai
Enter the 3 city
Nagpur
Enter the 4 city
Kolhapur
Enter the 5 city
Nashik
-*-*-*-*-*-*-*-Descending order of cities-*-*-*-*-*-*-*-*
Pune
Nashik
Nagpur
Mumbai
Kolhapur
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a java Program to accept ‘n’ no’s through the command line
NAME :: ROLL NO ::
Practical Name ::Write a java Program to accept ‘n’ no’s through the command line
and store all the prime no’s and perfect no’s into the different arrays
and display both the arrays.
Practical no. ::02
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
class PrimePerfectDemo
{
public static void main(String args[])
{
int i,j;
int no[]=new int[10];
int prime[]=new int[10];
int perfect[]=new int[10];
try
{
for(i=0;i<5;i++)
{
no[i]=Integer.parseInt(args[i]);
}
System.out.println("----------Prime Number----------");
for(i=0;i<5;i++)
{
int f=0;
for(j=2;j<no[i];j++)
{
if(no[i]%j==0)
{
f=1;
break;
}
}
if(f==0)
{
prime[i]=no[i];
System.out.println(prime[i]);
}
}
System.out.println("----------Perfect Number----------");
for(i=0;i<5;i++)
{
int s=0;
for(j=1;j<no[i];j++)
{
if(no[i]%j==0)
{
s=s+j;
}
}
if(no[i]==s)
{
perfect[i]=no[i];
System.out.println(perfect[i]);
}
}
}
catch(Exception e) {}
}
OutPut:-
E:\Slip_java_Sem-V\java Practical Slip2015\Slip (26)PrimePerfect Number\java>java PrimePerfectDemo 2 3 4 5 6
----------Prime Number----------
2
3
5
----------Perfect Number----------
6
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Define an Interface Shape with abstract method area(). Write a java
program to calculate an area of Circle and Sphere.(use final keyword)
Practical no. ::03
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
interface Shape
{
abstract void area();
}
class Cir implements Shape
{
float r,a,v;
Cir(float ra)
{
r=ra;
}
public final void area()
{
a=3.14f*r*r;
System.out.println("Area Of Circle is \t" + a);
}
}
class Sphere implements Shape
{
float rad,a;
Sphere(float r)
{
rad=r;
}
public final void area()
{
a=4*3.14f*rad;
System.out.println("Area Of Sphere is \t" + a);
}
}
class InterfaceDemo
{
public static void main(String args[])
{
Cir c=new Cir(5.0f);
c.area();
Sphere r=new Sphere(5.0f);
r.area();
}
}
OutPut:-
Area Of Circle is 78.5
Area Of Sphere is 62.800003
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Define an abstract class Shape with abstract methods area() and volume(). Write a java program to calculate area and volume of Cone and Cylinder.
Practical Name ::Define an abstract class Shape with abstract methods area() and volume(). Write a java program to calculate area and volume of Cone and Cylinder.
Practical no. ::04
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
abstract class shape
{
final double pi=3.14;
double rd,ht;
shape (double r,double h) //Constructor
{
rd=r;
ht=h;
}
abstract double area();
abstract double volume();
}
class cylinder extends shape
{
cylinder(double r,double h)
{
super(r,h);
}
double area() // Area Of cylinder
{
return((2*pi*rd*ht)+(2*pi*rd*rd));
}
double volume() //Volume Of cylinder
{
return(pi*rd*rd*ht);
}
}
class cone extends shape
{
cone(double r,double h)
{
super(r,h);
}
double area() // Area Of cone
{
return(pi*rd*ht);
}
double volume() //Volume Of cone
{
return(pi*rd*rd*ht);
}
}
public class ShapeDemo
{
public static void main(String args[])
{
System.out.println("----------------------------------------------------------");
System.out.println(" Area & Volume of Sphere & Cylinder & Cone");
cylinder cy=new cylinder(5.00,6.00);
cylinder s2;
s2=cy;
System.out.println("----------------------------------------------------------");
System.out.println(" Area Of cylinder : "+s2.area());
System.out.println(" Volume Of cylinder : "+s2.volume());
cone c=new cone(4.00,5.00);
cone s3;
s3=c;
System.out.println("----------------------------------------------------------");
System.out.println(" Area Of cone: "+s3.area());
System.out.println(" Volume Of cone : "+s3.volume());
System.out.println("----------------------------------------------------------");
}
}
OutPut:-
----------------------------------------------------------
Area & Volume of Sphere & Cylinder & Cone
----------------------------------------------------------
Area Of cylinder : 345.4
Volume Of cylinder : 471.0
----------------------------------------------------------
Area Of cone: 62.800000000000004
Volume Of cone : 251.20000000000002
----------------------------------------------------------
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a package for Games in Java, which have two classes Indoor
import Games.*;Practical Name ::Write a package for Games in Java, which have two classes Indoor
and Outdoor. Use a function display () to generate the list of players for the specific
games. (Use Parameterized constructor, finalize() method and Array Of Objects)
Practical no. ::05
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
class PackageDemo
{
public static void main(String args[])
{
Indoor In[] = new Indoor[3];
In[0] = new Indoor("Amit");
In[1] = new Indoor("Aniket");
In[2] = new Indoor("Amol");
System.out.println("Indoor Players...");
for(int i=0;i<In.length;i++)
In[i].display();
System.out.println("Indoor Players...");
Outdoor Out[] = new Outdoor[3];
Out[0] = new Outdoor("Anil");
Out[1] = new Outdoor("Ameya");
Out[2] = new Outdoor("Ajay");
for(int i=0;i<Out.length;i++)
Out[i].display();
}
}
Game Package
Indoor.java
package Games;
public class Indoor
{
String player;
public Indoor(String p)
{
player = p;
}
public void display()
{
System.out.println(player);
}
protected void finalize()
{
System.out.println("Terminating Indoor...");
}
}
Outdoor.java
package Games;
public class Outdoor
{
String player;
public Outdoor(String p)
{
player = p;
}
public void display()
{
System.out.println(player);
}
protected void finalize()
{
System.out.println("Terminating Outdoor...");
}
}
OutPut:-
Indoor Players...
Amit
Aniket
Amol
Indoor Players...
Anil
Ameya
Ajay
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a java program to accept n employee names from user, store
Practical Name ::Write a java program to accept n employee names from user, store
them into the LinkedList class and display them by using.
a. Iterator Interface
b. ListIterator Interface
Practical no. ::06
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.io.*;
import java.util.*;
class LinkedListDemo
{
public static void main(String args[])
{
int no,i;
String name;
LinkedList obj=new LinkedList();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Number of Employee:-");
no=Integer.parseInt(br.readLine());
for(i=0;i<no;i++)
{
System.out.println("Enter Employee Name:-"+(i+1));
name=br.readLine();
obj.add(name);
}
System.out.println("\nUsing Iterator");
Iterator itr=obj.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
System.out.println("\nUsing List Iterator");
ListIterator it=obj.listIterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
catch(IOException e){}
}
}
OutPut:-
Enter Number of Employee:-
5
Enter Employee Name:-1
Ramesh
Enter Employee Name:-2
Ram
Enter Employee Name:-3
Suraj
Enter Employee Name:-4
Swapnil
Enter Employee Name:-5
Santosh
Using Iterator
Ramesh
Ram
Suraj
Swapnil
Santosh
Using List Iterator
Ramesh
Ram
Suraj
Swapnil
Santosh
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name :: Write a java program to read n Students names from user, store them
Practical Name :: Write a java program to read n Students names from user, store them
into the ArrayList collection. The program should not allow duplicate
names. Display the names in Ascending order.
Practical no. ::07
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.io.*;
import java.util.*;
class ArrayListDemo
{
public static void main(String args[])
{
int no,i,j;
String name;
ArrayList obj=new ArrayList();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Number of Student:-");
no=Integer.parseInt(br.readLine());
String str[]=new String[no];
for(i=0;i<no;i++)
{
System.out.println("Enter student Name:-"+(i+1));
name=br.readLine();
if(obj.contains(name))
{
System.out.println("Element Allready Inserted!!!\n Reenter Element");
i--;
}
else
{
obj.add(name);
}
}
obj.toArray(str);
for(i=0;i<no;i++)
{
for(j=i+1;j<no;j++)
{
if((str[i].compareTo(str[j]))>0)
{
String temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
}
System.out.println("Sorted Element:");
for(i=0;i<no;i++)
System.out.println(str[i]);
}
catch(IOException e){}
}
}
OutPut:-
Enter Number of Student:-
5
Enter student Name:-1
Uttam
Enter student Name:-2
Sagar
Enter student Name:-3
Prashant
Enter student Name:-4
Vishal
Enter student Name:-5
Santosh
Sorted Element:
Prashant
Sagar
Santosh
Uttam
Vishal
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name :: Write a java program to accept Employee name from the user and
Practical Name :: Write a java program to accept Employee name from the user and
check whether it is valid or not. If it is not valid then throw user
defined Exception “Name is Invalid” otherwise display it.
Practical no. ::08
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.util.*;
class InvalidName extends Exception
{
InvalidName(String msg)
{
super(msg);
}
}
public class ExceptionDemo
{
String name,str;
char ch;
int j,flag=0;
DataInputStream din=new DataInputStream(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void userExce()
{
try
{
System.out.print("Enter the Employee Name : ");
str=br.readLine();
name=str;
for(int j=0;j<name.length();j++)
{
ch=(char)name.charAt(j);
if(Character.isDigit(ch))
{
flag=1;
}
if(Character.isLetter(ch))
{
}
else
{
flag=1;
}
}
if(flag==1)
{
throw new InvalidName("Name is Invalid");
//throws userdefined Exception.
}
else
{
System.out.println("Name="+name);
}
} // Closing of Try Block.
catch(InvalidName z)
{
System.out.println(z.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
} //Closing of userExce function.
public static void main(String args[])
{
ExceptionDemo n1=new ExceptionDemo();
n1.userExce();
}
}
OutPut:-
E:\java Practical Slip2015\Slip (11)InvalidName\Java>java ExceptionDemo
Enter the Employee Name : Amol
Name=Amol
E:\java Practical Slip2015\Slip (11)InvalidName\Java>java ExceptionDemo
Enter the Employee Name : 1234
Name is Invalid
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name :: Write a java program to read the characters from a file, if a character
Practical Name :: Write a java program to read the characters from a file, if a character
is alphabet then reverse its case, if not then display its category on the
Screen. (whether it is Digit or Space).
Practical no. ::09
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.util.*;
class Check
{
public static void main(String args[])
{
char ch;
String line="";
FileInputStream f1;
int i;
try
{
f1=new FileInputStream("a.txt");
Scanner scan=new Scanner(f1);
while(scan.hasNextLine())
{
line=scan.nextLine();
for(int j=0;j<line.length();j++)
{
ch=(char)line.charAt(j);
if (ch==' ') //if(Character.isSpaceChar(ch))
System.out.println("Character is Space");
if(Character.isDigit(ch)==true) // if(Character.isDigit(ch))
System.out.println("Character is digit");
i=(int)line.charAt(j);
if ((i>=65)&&(i<=91))
{
System.out.println("Character is Capital Alphabet ");
i=i+32;
ch=(char)i;
System.out.println(" Its Small Alphabet is : "+ch);
}
else if((i>=97)&&(i<=122))
{
System.out.println("Character is Small Alphabet ");
i=i-32;
ch=(char)i;
System.out.println(" Its Capital Alphabet is : "+ch);
}} } }
catch(Exception e){}
}
}
OutPut:-
Character is Small Alphabet
Its Capital Alphabet is : A
Character is Small Alphabet
Its Capital Alphabet is : B
Character is Small Alphabet
Its Capital Alphabet is : C
Character is Space
Character is Capital Alphabet
Its Small Alphabet is : d
Character is Capital Alphabet
Its Small Alphabet is : e
Character is Capital Alphabet
Its Small Alphabet is : f
Character is Space
Character is digit: 1
Character is digit: 2
Character is digit: 3
Character is digit: 4
Character is digit: 5
Character is digit: 6
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name :: Write a java program that displays the number of characters, lines &
Practical Name :: Write a java program that displays the number of characters, lines &
words from a file
Practical no. ::10
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
class FileCount
{
public static void main(String args[]) throws Exception
{
int ccnt=0,lcnt=1,wcnt=0,c;
FileInputStream fin=new FileInputStream("a.txt");
while((c=fin.read())!=-1)
{
ccnt++;
if(c==32 || c==13)
wcnt++;
if(c==13)
lcnt++;
}
System.out.println("Number of Characters are " + ccnt);
System.out.println("Number of Words are " + wcnt);
System.out.println("Number of Lines are " + lcnt);
}
}
OutPut:-
Number of Characters are 52
Number of Words are 8
Number of Lines are 2
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a java program to display the contents of a file in reverse order
Practical Name ::Write a java program to display the contents of a file in reverse order
Practical no. ::11
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.io.*;
import java.util.*;
class RevFile
{
public static void main(String args[])
{
char ch;
String line="";
FileInputStream f1;
int i=0;
try
{
f1=new FileInputStream("a.txt");
Scanner scan=new Scanner(f1);
while(scan.hasNextLine())
{
String st=scan.nextLine();
StringBuffer buf=new StringBuffer(st);
buf=buf.reverse();
String rs=buf.toString();
System.out.println(rs);
}
}
catch(Exception e) {}
}
}
OutPut:-
E:\java Practical Slip2015\Slip (9)FileRev\java>java RevFile
.idnawlapmip egelloC edakaK rD
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write an applet application in Java for designing Temple
Practical Name ::Write an applet application in Java for designing Temple
Practical no. ::12
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class DrawTemple extends Applet
{
public void paint(Graphics g)
{
g.drawRect(100,250,100,100);
g.drawRect(140,300,20,50);
g.drawLine(100,250,150,130);
g.drawLine(200,250,150,130);
g.drawLine(150,130,150,50);
g.drawRect(150,50,10,30);
}
}
DrawTemple.html
<html>
<applet code="DrawTemple" width=500 height=500></applet>
</html>
OutPut:-
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write an applet application in Java for smile face
Practical Name ::Write an applet application in Java for smile face
Practical no. ::13
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class DrawFace extends Applet
{
public void paint(Graphics g)
{
g.drawOval(130,200,150,130);
g.fillOval(150,250,20,20);
g.fillOval(230,250,20,20);
g.drawLine(200,235,200,290);
g.drawOval(100,250,30,30);
g.drawOval(280,250,30,30);
g.drawArc(175,260,50,50,180,180);
}
}
<html>
<applet code="DrawFace" width=500 height=500></applet>
</html>
OutPut:-
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a java program to design a following GUI (Use Swing).
Practical Name ::Write a java program to design a following GUI (Use Swing).
Practical no. ::14
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class SwingDemo extends JFrame
{
private JPanel jpInfo = new JPanel();
private JLabel lbName,lbLname,lbadd,lbmobno,lbgender,lbint,lbinfo;
private JTextField txt1,txt2,txt3,txt4;
private CheckboxGroup rdgroup;
Checkbox radio1,radio2,check1,check2,check3;
private JButton btnSubmit, btnreset;
SwingDemo()
{
rdgroup=new CheckboxGroup();
jpInfo.setBounds (0, 0, 500, 115);
jpInfo.setLayout (null);
lbinfo = new JLabel ("Personal Informaction:");
lbinfo.setBounds (80, 20, 150, 25);
lbName = new JLabel ("First Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
txt1 = new JTextField ();
txt1.setBounds (100,55,150,25);
lbLname = new JLabel ("Last Name:");
lbLname.setForeground (Color.black);
lbLname.setBounds (15, 75, 80, 25);
txt2 = new JTextField ();
txt2.setBounds (100,75,150,25);
lbadd = new JLabel ("Address:");
lbadd.setForeground (Color.black);
lbadd.setBounds (15, 95, 80, 25);
txt3 = new JTextField ();
txt3.setBounds (100,95,150,25);
lbmobno = new JLabel ("Mobile No:");
lbmobno.setForeground (Color.black);
lbmobno.setBounds (15, 125, 80, 25);
txt4 = new JTextField ();
txt4.setBounds (100,125,150,25);
lbgender = new JLabel ("Gender");
lbgender.setBounds (15, 145, 80, 25);
radio1=new Checkbox("Male",rdgroup,true);
radio1.setBounds (100, 150,50,20);
radio2=new Checkbox("Female",rdgroup,true);
radio2.setBounds (150, 150,100,20);
lbint=new JLabel ("Your Interest:");
lbint.setBounds (15,170,80,30);
check1=new Checkbox("Computer");
check1.setBounds (100,175,80,20);
check2=new Checkbox("Sport");
check2.setBounds (190,175,50,20);
check3=new Checkbox("Music");
check3.setBounds (250,175,50,20);
//Aligning The Buttons.
btnSubmit = new JButton ("Submit");
btnSubmit.setBounds (20, 230, 100, 25);
btnreset=new JButton("Reset");
btnreset.setBounds(120,230,100,25);
//Adding the All the Controls to Panel.
jpInfo.add (lbName);
;
jpInfo.add (lbLname);
jpInfo.add (lbadd);
jpInfo.add (lbmobno);
jpInfo.add (lbgender);
jpInfo.add (lbinfo);
jpInfo.add (txt1);
jpInfo.add (txt2);
jpInfo.add (txt3);
jpInfo.add (txt4);
jpInfo.add (check1);
jpInfo.add (check2);
jpInfo.add (check3);
jpInfo.add (radio1);
jpInfo.add (radio2);
jpInfo.add (lbint);
jpInfo.add (btnSubmit);
jpInfo.add( btnreset);
//Adding Panel to Window.
getContentPane().add (jpInfo);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//In the End Showing the New Account Window.
setVisible (true);
setSize(350,350);
setTitle("Personal Informaction");
}
public static void main(String args[])
{
new SwingDemo();
}
}
OutPut:-
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a java program to display “Hello Java” with settings Font-
Frame (Use Label)
Practical Name ::Write a java program to display “Hello Java” with settings Font-
Georgia, Foreground color- Red, background color – Blue on the
Frame (Use Label)
Practical no. ::15
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
public class StringDemo extends Frame
{
Font f;
Label l1,l2;
public StringDemo()
{
setLayout(new FlowLayout());
l1=new Label("Hello Java");
l1.setForeground(Color.RED);
l1.setFont(new Font("Georgia ", Font.BOLD, 12));
setBackground(Color.BLUE);
add(l1);
}
public static void main(String args[])
{
StringDemo f1=new StringDemo();
f1.setTitle("String operation");
f1.setSize(300,300);
f1.setVisible(true);
}
}
OutPut:-
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a Java Program to accept the details of Employee(Eno,
EName,Sal) from the user and display it on the next Frame. (Use AWT)
Practical Name ::Write a Java Program to accept the details of Employee(Eno,
EName,Sal) from the user and display it on the next Frame. (Use AWT)
Practical no. ::16
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.awt.event.*;
class nextFrame extends Frame
{
Label l1,l2,l4;
TextField tf1,tf2,tf4;
nextFrame nf1;
public nextFrame(int no1,String name1,int sal1)
{
setLayout(new GridLayout(4,2));
l1=new Label("Emp No : ");
l2=new Label("Emp Name : ");
l4=new Label("Emp Salary : ");
tf1=new TextField(14);
tf2=new TextField(14);
tf4=new TextField(14);
add(l1);
add(tf1);
add(l2);
add(tf2);
add(l4);
add(tf4);
tf1.setText(String.valueOf(no1));
tf2.setText(name1);
tf4.setText(String.valueOf(sal1));
}
}
public class Employee extends Frame implements ActionListener
{
Frame f;
private Label l1,l2,l4;
private Button b1,b2;
private TextField tf1,tf2,tf4;
static Employee e1;
public Employee()
{
setLayout(new GridLayout(5,2));
l1=new Label("Enter Emp No : ");
l2=new Label("Enter Emp Name : ");
l4=new Label("Enter Emp Salary : ");
b1=new Button("Display");
b2=new Button("Exit");
tf1=new TextField(14);
tf2=new TextField(14);
tf4=new TextField(14);
add(l1);
add(tf1);
add(l2);
add(tf2);
add(l4);
add(tf4);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int no,sal;
String name,address;
if(e.getSource()==b1)
{
no=Integer.parseInt(tf1.getText());
name=tf2.getText();
sal=Integer.parseInt(tf4.getText());
f = new nextFrame(no,name,sal);
f.setTitle("Employee Detail");
f.setSize(250, 250);
f.setVisible(true);
}
else if(e.getSource()==b2)
{
System.exit(0);
}
}
public static void main(String args[])
{
e1=new Employee();
e1.setTitle("Employee Information");
e1.setSize(300,300);
e1.setVisible(true);
}
}
OutPut:-
/***************************************************************************/
NAME :: ROLL NO ::
Practical Name ::Write a Java program which will create a frame if we try to close it, it
should change it’s color and it remains visible on the screen(Use swing).
Practical Name ::Write a Java program which will create a frame if we try to close it, it
should change it’s color and it remains visible on the screen(Use swing).
Practical no. ::17
Date :: Remark ::
/***************************************************************************/
Date :: Remark ::
/***************************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class swingDemo extends JFrame
{
JPanel p = new JPanel();
swingDemo()
{
setVisible(true);
setSize(400,400);
setTitle("Swing Background");
add(p);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
p.setBackground(Color.BLACK);
JOptionPane.showMessageDialog(null,"Login Successful","Login",JOptionPane.INFORMATION_MESSAGE);
}
});
}
public static void main(String args[])
{
new swingDemo().show();
}
}
OutPut:-








No comments:
Post a Comment