JAVA PROGRAMMING
PART-A
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 1
JAVA PROGRAMMING
/* 1. Program to assign two integer values to x and y. Using the 'if' statement the output of the
program should display a message whether x is greater than y.*/
class Largest
{
public static void main (String args[])
{
int x=51;
int y=5;
if(x>y)
[Link]("Largest is x="+x);
else
[Link]("Largest is y="+y);
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 2
JAVA PROGRAMMING
/* 2. Program to list the factorial of the numbers 1 to 10. To calculate the factorial value, use
while loop. */
public class Factorial
{
public static void main (String args[])
{
int count=1;
long fact=1;
[Link]("Number \t\t\t Factorial");
while(count<=10)
{
fact*=count;
[Link](count+"\t\t\t\t"+fact);
count++;
}
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 3
JAVA PROGRAMMING
/* 3. Program to add two integers and two float numbers. When no arguments are supplied,
give a default value to calculate the sum. Use function overloading. */
class Functionoverloading
{
public void add(int x,int y)
{
int sum;
sum=x+y;
[Link](sum);
}
public void add(double a,double b)
{
double total;
total=a+b;
[Link](total);
}
}
class Mainfunover
{
public static void main(String args[])
{
Functionoverloading obj=new Functionoverloading();
[Link](10,20);
[Link](10.40,10.30);
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 4
JAVA PROGRAMMING
/*4. Program to perform mathematical operations. Create a class AddSub with methods to
add and substract. Create another class called MulDiv that extends from Add,Sub class to use
the member data of the super class. MulDiv should have methods to multiply and divide a
main function should access the methods and perform the mathematical operations. */
class AddSub
{
int x=20;
int y=15;
public void add( )
{
int sum;
sum=x+y;
[Link](sum);
}
public void sub( )
{
int minus;
minus=x-y;
[Link](minus);
}
}
class MulDiv extends AddSub
{
public void mul( )
{
int product;
product=x*y;
[Link](product);
}
public void div( )
{
int Rem;
Rem=x/y;
[Link](Rem);
}
}
class Operations
{
public static void main(String args[ ])
{
MulDiv obj=new MulDiv( );
[Link]( );
[Link]( );
[Link]( );
[Link]( );
}
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 5
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 6
JAVA PROGRAMMING
/* 5. Program with class variable that is available for all instances of a class. Use static
variable declaration observe the changes that occur in the object's member variable values. */
class staticDemo
{
static int count=0;
public void increment( )
{
count++;
}
public static void main(String args[ ])
{
staticDemo obj1=new staticDemo( );
staticDemo obj2=new staticDemo( );
[Link]( );
[Link]( );
[Link]("obj1:count is="+[Link]);
[Link]("obj2:count is="+[Link]);
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 7
JAVA PROGRAMMING
/* 6. a). Program to find the area and circumference of the circle by accepting the radius from
the user. */
import [Link];
import [Link];
public class Coc
{
public static void main(String args[])
{
double circumference,radius,area;
Scanner sc=new Scanner([Link]);
[Link]("Enter the radius of the circle:");
radius=[Link]();
circumference=[Link]*2*radius;
area=[Link]*radius*radius;
[Link]("area of a circle is"+area);
[Link]("the circumference of the circle is:"+circumference);
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 8
JAVA PROGRAMMING
/* 6.b). Program to accept a number and find whether the number is prime or not. */
import [Link].*;
class Prime
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the no");
int n=[Link]();
int i=1,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
[Link](n+"is a Prime no");
}
else
{
[Link](n+"is not a prime no");
}
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 9
JAVA PROGRAMMING
/* 7. Program to create a student class with following attributes. Enrollment No: Name, Mark
of sub1, Mark of Sub2, Mark of sub3, Total Marks. Total of the three marks must be
calculated only when the student passes in all three subjects. The pass mark for each subject
is 50. If a candidate fails in any one of the subjects, his total mark must be declared as zero.
Using this condition write a constructor for this class. Write separate functions for accepting
and displaying student details. In the main method create an array of three student objects and
display the details. */
import [Link];
class student
{
int rollno;
String sname;
int s1,s2,s3;
int total;
student()
{
total=0;
}
void set()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter student details: rollno, name,s1,s2,s3");
rollno=[Link]();
sname=[Link]();
s1=[Link]();
s2=[Link]();
s3=[Link]();
if(s1>50 && s2>50 && s3>50)
total=s1+s2+s3;
}
void disp()
{
[Link](rollno+"\t"+sname+"\t"+s1+"\t"+s2+"\t"+s3+"\t"+total);
}
public static void main(String args[])
{
student s[]=new student[3];
for(int i=0;i<3;i++)
{
s[i]=new student();
s[i].set();
}
[Link]("rollno\t Name\t M1\t M2\t M3\t total\n");
for(int i=0;i<3;i++)
s[i].disp();
}
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 10
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 11
JAVA PROGRAMMING
/*8. In a college first year class are having the following attributes Name of the class (BCA,
BCom, BSc,BBA),Name of the staff No of the students in the class, Array of students in the
class.*/
class Fclass
{
String nameofclass,nameofstaff;
int noofstds;
Fclass(String noc,String nos,int numstd)
{
nameofclass=noc;
nameofstaff=nos;
noofstds=numstd;
}
void display()
{
[Link](nameofclass+"\t"+nameofstaff+"\t"+noofstds);
}
}
class Firstyear
{
public static void main(String args[])
{
Fclass std[]=new Fclass[4];
std[0]=new Fclass("BCA","RAVI KUMAR",139);
std[1]=new Fclass("BBA","KHADRI S S",110);
std[2]=new Fclass("BCom ","SHIVARAJ",100);
std[3]=new Fclass("BSc","SAVITHA B",90);
[Link]("course\t staff\t Number of students");
for(int i=0;i<4;i++)
std[i].display();
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 12
JAVA PROGRAMMING
/*9. Define a class called first year with above attributes and define a suitable constructor.
Also write a method called best student() which process first-year object and return the
student with the highest total mark. In the main method define a first-year object and find the
best student of this class. */
import [Link];
public class FirstYear
{
public String cname;
public String sname;
public int rollno;
public int m1, m2, m3, total;
public FirstYear( )
{
cname = "BCA"; m1 = m2 = m3 = total = 0;
}
public FirstYear(String cname)
{
[Link] = cname;
m1 = m2 = m3 = total = 0;
}
public void setStudent( )
{
Scanner sc = new Scanner([Link]);
[Link]("Enter student details: name, roll no, m1, m2, m3:");
sname = [Link]( );
rollno =[Link]( );
m1 =[Link]( );
m2 =[Link]( );
m3 =[Link]( );
total = m1 + m2 + m3;
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 13
JAVA PROGRAMMING
}
public void display( )
{
[Link](cname + "\t" + rollno + "\t" + sname + "\t" + m1 + "\t" + m2 + "\t"
+ m3 + "\t" + total);
}
public static void main(String args[ ])
{
FirstYear s[ ] = new FirstYear[60];
int max = 0;
String beststudent = "";
int n;
Scanner sc = new Scanner([Link]);
[Link]("Enter no of students:");
n = [Link]( );
for ( int i = 0; i < n; i++)
{
s[i] = new FirstYear( );
s[i].setStudent( );
if (s[i].total > max)
{
max = s[i].total;
beststudent =s[i].sname;
}
}
[Link]("Course \tRollNo \tName \tM1 \tM2 \tM3 \tTotal");
for (int i=0; i < n ; i++)
{
s[i].display( );
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 14
JAVA PROGRAMMING
[Link]("\nBest Student: " + beststudent);
[Link]("Marks: " + max);
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 15
JAVA PROGRAMMING
/* 10. Program to define a class called Employee with the name and the date of appointment.
Create ten Employee objects as an array and sort them as per their date of appointment i.e,
print them as per their seniority. */
import [Link].*;
class Employee
{
String name;
Date appdate;
public Employee(String nm,Date apdt)
{
name=nm;
appdate=apdt;
}
public void display()
{
[Link]("EmployeeName:"+name+"[Link]()+"/"+a
[Link]()+"/"+[Link]();
}
}
class Empsort
{
public static void main (String args[])
{
Employee emp[]=new Employee[10];
emp[0]=new Employee("Shaha PD",new Date(1999,05,22));
emp[1]=new Employee("Patil AS",new Date(2000,01,12));
emp[2]=new Employee("Phadake PV",new Date(2009,04,25));
emp[3]=new Employee("Shide SS",new Date(2005,02,19));
emp[4]=new Employee("Shrivatsav RT",new Date(2010,02,01));
emp[5]=new Employee("Ramanjineya",new Date(2013,03,01));
emp[6]=new Employee("Jennifar",new Date(2014,04,01));
emp[7]=new Employee("Anjum",new Date(2022,05,01));
emp[8]=new Employee("Samant",new Date(2012,06,01));
emp[9]=new Employee("Channa",new Date(2011,07,01));
[Link]("\nList of employees\n");
for(int i=0;i<[Link];i++)
emp[i].display();
for(int i=0;i<[Link];i++)
{
for(int j=0;j<[Link];j++)
{
if(emp[i].[Link](emp[j].appdate))
{
Employee t=emp[i];
emp[i]=emp[j];
emp[j]=t;
}
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 16
JAVA PROGRAMMING
}
[Link]("\n list of Employees Seniority wise\n");
for(int i=0;i<[Link];i++)
emp[i].display();
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 17
JAVA PROGRAMMING
/*11. Create a package [Link] time [Link] in your current working directory.
a) Create a default class student in the above package with the following attributes:
Name,age,sex./*
package [Link];
import [Link];
public class Studentpkg
{
public String name,gender;
public int age;
public void accept()
{
[Link]("Enter the name");
Scanner scan=new Scanner([Link]);
name=[Link]();
[Link]("Enter the gender");
gender=[Link]();
[Link]("Enter the age");
Scanner scan1=new Scanner([Link]);
age=[Link]();
}
public void display()
{
[Link]("\n student Information\n");
[Link]("Name:"+name+"\n"+"Gender"+gender+"\n"+"Age"+age+"\n");
}
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 18
JAVA PROGRAMMING
/*b) Have methods for storing as well as displaying.
package [Link];
import [Link];
public class StudentP
{
public static void main(String args[])
{
Studentpkg S1=new Studentpkg();
[Link]();
[Link]();
}
}
OUTPUT:
Enter the name:Ram
Enter the Gender:Male
Enter the Age:19
Student Information:
Name:Ram
Gender:Male
Age:19
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 19
JAVA PROGRAMMING
PART-B
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 20
JAVA PROGRAMMING
/* 1. Program to catch Negative Array Size Exception. This exception is caused when the
array is initialized to negative values.*/
public class NegativeArraySizeExceptionExample
{
public static void main(String args[])
{
try
{
int array[]=new int[-5];
}
catch(NegativeArraySizeException nase)
{
[Link]();
}
[Link]("continuing execution...");
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 21
JAVA PROGRAMMING
/* 2. Program to handle NullPointerException and use the "Finally" method to display a
message to the user. */
import [Link].*;
class Exceptionfinally
{
public static void main(String args[])
{
String ptr=null;
try
{
if([Link]("gfg"))
[Link]("same");
else
[Link]("not same");
}
catch(NullPointerException e)
{
[Link]("Null Pointer Exception Caught");
}
finally
{
[Link]("finally block is always executed");
}
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 22
JAVA PROGRAMMING
/* 3. Program which create and displays a message on the window.*/
import [Link].*;
import [Link].*;
import [Link].*;
class Message implements ActionListener
{
public static void main(String args[])
{
JFrame frame=new JFrame("Original Frame");
[Link](300,300);
[Link](JFrame.EXIT_ON_CLOSE);
Message obj=new Message();
JButton b1=new JButton("view Message");
[Link](b1);
[Link](obj);
[Link](true);
}
public void actionPerformed(ActionEvent e)
{
JFrame sub_frame=new JFrame("Sub Frame");
sub_frame.setSize(200,200);
JLabel lbl=new JLabel("!!! Hello !!!");
sub_frame.add(lbl);
sub_frame.setVisible(true);
}
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 23
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 24
JAVA PROGRAMMING
/* 4. Program to draw several shapes in the created window. */
import [Link].*;
import [Link].*;
public class Shapes extends Applet
{
public void paint(Graphics g)
{
[Link](new Font("Cambria",[Link],15));
[Link]("Different Shapes",15,15);
[Link](10,20,50,60);
[Link](10,70,40,40);
[Link]([Link]);
[Link](60,20,30,90);
[Link](60,135,80,40,180,180);
[Link](20,120,60,30,5,5);
}
}
/* <applet code="Shapes" width=200 height=200> </applet> */
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 25
JAVA PROGRAMMING
/* 5. Program to create an applet and draw gridlines. */
import [Link].*;
import [Link].*;
public class chessboard extends Applet
{
public void paint(Graphics g)
{
int row,column,x,y;
for(row=0;row<8;row++)
{
for(column=0;column<8;column++)
{
x=column*20;
y=row*20;
if((row%2)==(column%2))
[Link]([Link]);
else
[Link]([Link]);
[Link](x,y,20,20);
}
}
}
}
/* <applet code="chessboard" width=200 height=200> </applet> */
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 26
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 27
JAVA PROGRAMMING
/* 6. Program which creates a frame with two buttons father and mother. When we click the
father button the name of the father his age and designation must appear. */
import [Link].*;
import [Link].*;
public class FatherMother extends Frame implements ActionListener
{
Button b1,b2;
Label lbl;
FatherMother()
{
b1=new Button("Father");
[Link](50,40,170,40);
add(b1);
[Link](this);
b2=new Button("Mother");
[Link](200,40,170,40);
add(b2);
lbl=new Label();
[Link](50,80,400,200);
add(lbl);
[Link](this);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==b1)
[Link]("Name:Chiranjeevi Age:66 Designation:Manager");
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 28
JAVA PROGRAMMING
else
[Link]("Name:Kousalya Age:56 Dessignation:[Link]");
}
public static void main(String args[])
{
FatherMother a=new FatherMother();
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 29
JAVA PROGRAMMING
/* 7. Create a frame which displays your personal details with respect to a button click. */
import [Link].*;
import [Link].*;
class Personal extends Frame implements ActionListener
{
Button b1;
Label lbl;
Personal()
{
b1=new Button("Display");
lbl=new Label();
[Link](30,90,90,30);
[Link](250,250,250,120);
[Link](" ");
setSize(400,350);
setVisible(true);
add(b1);
[Link](this);
add(lbl);
}
public void actionPerformed(ActionEvent e)
{
[Link]("Name:Raja,Age:20,Course:BSC 2nd sem");
}
public static void main(String args[])
{
Personal p=new Personal();
}
}
/* <applet code="[Link]" width="200" height="200"> </applet> */
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 30
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 31
JAVA PROGRAMMING
/* 8. Create a simple applet which revels the personal information of yours. */
import [Link];
import [Link];
public class First extends Applet
{
public void paint(Graphics g)
{
[Link]("Name:Vindhya Rani",150,150);
[Link]("Age:20",200,200);
[Link]("Course:Bsc",250,250);
[Link]("Percentage:85",300,300);
}
}
/* <applet code="[Link]" width="400" height="400"></applet> */
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 32
JAVA PROGRAMMING
/* 9. Program to move different shapes according to the arrow key pressed. */
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class MoveShapes extends Applet implements KeyListener
{
private int x=20,y=20;
private int Width=100,Height=100;
private int inc=5;
private Color myColor=[Link];
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent e)
{
int code=[Link]();
if(code==KeyEvent.VK_LEFT)
{
x-=inc;
if(x<getWidth())
x=20;
repaint();
}
else if(code==KeyEvent.VK_RIGHT)
{
x+=inc;
if(x>getWidth())
x=getWidth()-100;
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 33
JAVA PROGRAMMING
repaint();
}
else if(code==KeyEvent.VK_DOWN)
{
y+=inc;
if(y>getHeight())
y=getHeight()-100;
repaint();
}
else if(code==KeyEvent.VK_UP)
{
y-=inc;
if(y<getHeight())
y=20;
repaint();
}
}
public void paint(Graphics g)
{
[Link]("Click to activate",7,20);
[Link]([Link]);
[Link](x,y,Width,Height);
[Link]([Link]);
[Link](x+100,y+100,Width,Height);
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
}
/*<applet code="[Link]" width="400" height="400"> </applet> */
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 34
JAVA PROGRAMMING
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 35
JAVA PROGRAMMING
/* 10. Program to create a window when we press M or m the window displays Good
Morning, A or a the window displays Good Afternoon, E or e the window displays Good
Evening, N or n the window displays Good Night. */
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Key extends Applet implements KeyListener
{
static String
str="Hello";
public void init()
{
setBackground([Link]);
Font f=new Font("arial",[Link],20);
setFont(f);
addKeyListener(this);
}
public void paint(Graphics g)
{
[Link]("Click here to activate",100,100);
[Link]("Type M/m--->To Good Morning",100,200);
[Link]("Type A/a--->To Good Afternoon",100,300);
[Link]("Type E/e--->To Good Evening",100,400);
[Link]("Type N/n--->To Good Night",100,500);
[Link]([Link]);
[Link](str,600,200);
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 36
JAVA PROGRAMMING
public void keyTyped(KeyEvent e)
{
char key=[Link]();
if(key=='M'||key=='m')
{
str="GOOD MORNING";
repaint();
}
else if(key=='A'||key=='a')
{
str="GOOD AFTERNOON";
repaint();
}
if(key=='E'||key=='e')
{
str="GOOD EVENING";
repaint();
}
if(key=='N'||key=='n')
{
str="GOOD NIGHT";
repaint();
}
switch(key)
{
case'M':
case'm':str="GOOD MORNING";repaint();break;
case'A':
case'a':str="GOOD AFTERNOON";repaint();break;
case'E':
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 37
JAVA PROGRAMMING
case'e':str="GOOD EVENING";repaint();break;
case'N':
case'n':str="GOOD NIGHT";repaint();break;
}
}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
}
/*<applet code="[Link]" width="300" height="300"> </applet> */
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 38
JAVA PROGRAMMING
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 39
JAVA PROGRAMMING
/* 11. Demonstrate the various mouse handling events using suitable example. */
import [Link].*;
import [Link].*;
public class MainM extends Frame implements MouseListener
{
Label lbl;
MainM()
{
super("AWT Frame");
lbl=new Label();
[Link](25,60,250,30);
[Link]([Link]);
add(lbl);
setSize(300,300);
setLayout(null);
setVisible(true);
[Link](this);
}
public void windowClosing(WindowEvent e)
{
dispose();
}
public static void main(String args[])
{
new MainM();
}
public void mouseClicked(MouseEvent e)
{
[Link]("Mouse Clicked");
}
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 40
JAVA PROGRAMMING
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e)
{
[Link]("Mouse Entered");
}
public void mouseExited(MouseEvent e)
{
[Link]("Mouse Exited");
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 41
JAVA PROGRAMMING
/*12. Program to create menu bar and pull down menus. */
import [Link].*;
class MenuExample
{
MenuExample()
{
Frame f=new Frame("Menu and MenuItem Example");
MenuBar mb=new MenuBar();
Menu menu=new Menu("Menu");
Menu SubMenu=new Menu("Sub Menu");
MenuItem i1=new MenuItem("Item 1");
MenuItem i2=new MenuItem("Item 2");
MenuItem i3=new MenuItem("Item 3");
MenuItem i4=new MenuItem("Item 4");
MenuItem i5=new MenuItem("Item 5");
[Link](i1);
[Link](i2);
[Link](i3);
[Link](i4);
[Link](i5);
[Link](SubMenu);
[Link](menu);
[Link](mb);
[Link](400,400);
[Link](null);
[Link](true);
}
public static void main(String args[])
{
new MenuExample();
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 42
JAVA PROGRAMMING
}
}
OUTPUT:
DEPARTMENT OF COMPUTER SCIENCE, SKNG GFG COLLEGE, GANGAVATHI 43