0% found this document useful (0 votes)
4 views3 pages

Java Pro9

The document contains a Java applet code that creates a simple GUI with a button to display a menu window. The menu includes options for 'BANANA', 'APPLE', and 'ORANGE', and updates a label based on the user's selection. It also handles window closing events to hide the menu window properly.

Uploaded by

cringerasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java Pro9

The document contains a Java applet code that creates a simple GUI with a button to display a menu window. The menu includes options for 'BANANA', 'APPLE', and 'ORANGE', and updates a label based on the user's selection. It also handles window closing events to hide the menu window properly.

Uploaded by

cringerasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.awt.

*;

import java.awt.event.*;

import java.applet.Applet;

Public class PRO9 extends Applet implements ActionListener

Button b1;

frame menuWindow;

public void init()

b1=new Button("Display the menu Window");

add(b1);

b1.addActionListener(this);

menuWindow=new frame("menu");

menuWindow.setSize(200,200);

public void actionPerformed(ActionEvent e)

if(e.getSource()==b1)

menuWindow.setVisible(true);

}}

class frame extends Frame implements ActionListener

Menu menu;

MenuBar menubar;
MenuItem mitem1,mitem2,mitem3;

Label label1;

frame(String title)

super(title);

label1=new Label("Welcome from java");

setLayout(new GridLayout(1,1));

add(label1);

menubar=new MenuBar();

menu=new Menu("file");

mitem1=new MenuItem("BANANA");

menu.add(mitem1);

mitem1.addActionListener(this);

mitem2=new MenuItem("APPLE");

menu.add(mitem2);

mitem2.addActionListener(this);

mitem3=new MenuItem("ORANGE");

menu.add(mitem3);

mitem3.addActionListener(this);

menubar.add(menu);

setMenuBar(menubar);

addWindowListener(new WindowAdapter()

public void WindowClosing(WindowEvent e)

{
setVisible(false);

});

public void actionPerformed(ActionEvent event)

if(event.getsource()==mitem1)

label1.setText("U Choose a Banana");

if(event.getSource()==mitem2)

label1.setText("U Choose a Apple");

if(event.getsource()==mitem3)

label1.setText("U Choose a Orange");

You might also like