You are on page 1of 82

INTRODUCTION

Abstract Window Toolkit (AWT) is an API to develop GUI or window –


based applications in java.

A graphical user interface is built of graphical elements called


components. Typical components include such items as buttons, scrollbars, and
text fields.

Java AWT Components are platform dependent that is


components are
displayed according to the view of operating system.

The Container class is a subclass of Component. Container class used to


display non-container class.

In java GUI can be design using some predefined classes. All these
classes are defined in java.awt package.
java.awt class
The AWT provides nine basic non-container component and three container
classes.
AWT Classes
• The AWT classes are contained in the java.awt package.
• It is one of Java’s largest packages.Fortunately, because it is logically organized
in a top-down, hierarchical fashion,
Component
 At the top of the AWT hierarchy is the Component class.

 Component is an abstract class that encapsulates all of the attributes of a visual


component.
 It defines over a hundred public methods that are responsible for managing events,
such as mouse and keyboard input, positioning and sizing the window,
and repainting.
 A Component object is responsible for remembering the current foreground and
background colors and the currently selected text font.
Container
• The Container class is a subclass of Component.

• It has additional methods that allow other Component objects to be nested


within it.

• Other Container objects can be stored inside of a Container (since they are
themselves instances of Component).

• This makes for a multileveled containment system. A container is responsible for


laying out (that is, positioning) any components that it contains.
Panel
• The Panel class is a concrete subclass of Container. A Panel may be thought of
as a recursively nestable, concrete screen component.
• Panel is the superclass for Applet. When screen output is directed to an applet, it
is drawn on the surface of a Panel object.
• Panel is a window that does not contain a title bar, menu bar, or border.
• This is why you don’t see these items when an applet is run inside a browser.
When you run an applet using an applet viewer, the applet viewer provides the
title and border.
• Other components can be added to a Panel object by its add( ) method (inherited
from Container).
• Once these components have been added, you can position and resize them
manually using the setLocation( ), setSize( ), setPreferredSize( ), or setBounds(
) methods defined by Component
Window
• The Window class creates a top-level window.
• A top-level window is not contained within any other object; it sits directly on the
desktop.
• Generally, you won’t create Window objects directly. Instead, you will use a subclass
of Window called Frame

Frame
• Frame encapsulates what is commonly thought of as a “window.” It is a subclass of
Window and has a title bar, menu bar, borders, and resizing corners.

Canvas
• Although it is not part of the hierarchy for applet or frame windows, there is one other
type of window that you will find valuable: Canvas. Derived from Component,
• Canvas encapsulates a blank window upon which you can draw.
Container class

Window The window is the container that have no borders and menu bars.
- You must use frame, dialog or another window for creating a window.

Frame - The Frame is the container that contain title bar and can have menu
bars. It can have other components like button, text field etc.

Panel - The Panel is the container that doesn't contain title bar and menu
bars. It can have other components like button, text field and etc.

Canvas - It represents a rectangular area where application can draw


something or can receive inputs created by user.

Before adding the components that make up a user interface, the programmer must
create a container.
Creating Frame
Create a subclass of Frame

override any of the standard window methods,such as


init(),start(),stop(),and paint().

implement the windowClosing() method of the windowlistener


interface . Calling setVisible(false)when the window is closed.

Once you have defined a Frame subclass,you can create an object of that
class.But it will note be initially visible When created,the window is given a
default height and width

You can set the size of the window explicitly by calling the following
method
void setSize(int height,int width);
void setSize(dimension d);

dimension d=new dimension(400,400);


Frame Methods

setTitle(String) - used to set display user defined


message on title bar.

setBackground(color) - used to set background color.

setForeground(color) - used to set Foreground or text color.

setSize(dimension) - set the width and height for frame

setVisible(boolean) - set frame is visible or not.

setLayout() - used to set any layout to the frame .

add(component) - add component to the frame.


Frame example

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class SampleFrame extends Frame {
SampleFrame(String title) {
super(title);
MyWindowAdapter adapter = new MyWindowAdapter(this);
addWindowListener(adapter);
}
public void paint(Graphics g) {
g.drawString("This is in frame window", 40, 40);
}
}
class MyWindowAdapter extends WindowAdapter {
SampleFrame sf;
public MyWindowAdapter(SampleFrame sf) {
this.sf = sf;
}
Frame example (cont.,)
public void windowClosing(WindowEvent we) {
sf.setVisible(false);
}
}
public class testFrame extends Applet {
Frame f;
public void init() {
f = new SampleFrame("A
Frame Window");
f.setSize(500, 500);
f.setVisible(true);
}
public void start() {
f.setVisible(true);
}
public void stop() {
f.setVisible(false);
}
}
OUTPUT
EVENT HANDLING
EVENT HANDLING (Cont)
HOW TO USE EVENTS

Components defined in the AWT generate AWTEvents

Identify which events you wish to listen for (some components generate
more than one type of event)

Identify the Listener class which Listens for that event

Once we have identified the Listener interface, implement the Listener


interface

Our listener class must register with the component to received


events

Call the addXXXListener method where XXX is the Event type.


AWT EVENT

The following is a list of events in the java.awt.event package:

ActionEvent - Action has occurred (eg. Button


pressed)
AdjustmentEvent - "Adjustable" Component
changed
ComponentEvent - Component Changed
ContainerEvent - Container changed (add or
FocusEvent remove)
ItemEvent - Focus Changed
KeyEvent - Item Selected or Deselected
MouseEvent - Keyboard event
TextEvent - Mouse event
WindowEvent - Text Changed events
- Window related Events
LISTENER INTERFACE

The Following events have Listeners associated with them:

ActionEvent - ActionListener
AdjustmentEvent - AdjustmentListener
- ComponentListener
ComponentEvent - ContainerListener
ContainerEvent - FocusListener
FocusEvent - ItemListener
ItemEvent - KeyListener
KeyEvent - MouseListener
MouseEvent - MouseMotionListener
TextEvent - TextListener
WindowEvent - WindowListener
ActionEvent

The ActionEvent is generated when button is clicked or the item of a


list is double clicked.

To write an Action Listener,follow the steps given below:

First declare an event handler class and specify that the class either
implements an ActionListener interface or extends a class that implements
an ActionListener interface.
For example
public class MyClass implements ActionListener
{
//abstract methods of ActionListener inteface
}
ActionEvent Listener (cont)

Register an instance of the event handler class as a listener on one or more


components.
For example:
someComponent.addActionListener(instanceOfMyClass)

Include code that implements the methods in listener interface.

public void actionPerformed(ActionEvent e)


{
if(e.getSouce()==someComponent)
{
//code that reacts to the action
}
}
KeyEvent

On entering the character from any source generates the key event.This
interface has 3 methods. These are

public void keyTyped(KeyEvent ae)


{
//active on typing a code…..
}
public void keyPressed(KeyEvent ae)
{
//active on pressing a key……
}
public void keyReleased(KeyEvent ae)
{
//active on realesing a key…..
}
Key Event example

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Key extends Applet implements KeyListener {
int X=20,
Y=30;
String msg="KeyEvents--->";
public void init() {
addKeyListener(this);
setBackground(Color.green);
setForeground(Color.blue);
}
public void keyPressed(KeyEvent k) {
showStatus("KeyDown");
int key=k.getKeyCode();
Key Event example
switch(key) {
case KeyEvent.VK_UP: //constant for non-numpad up arrow key
showStatus("Move to Up");
break;
case KeyEvent.VK_DOWN: //constant for non-numpad down arrow key
showStatus("Move to Down");
break;
case KeyEvent.VK_LEFT: //constant for non-numpad left arrow key
showStatus("Move to Left");
break;
case KeyEvent.VK_RIGHT: //constant for non-numpad right arrow key
showStatus("Move to Right");
break;
}
repaint();
}
Key Event example

public void keyReleased(KeyEvent k) {


showStatus("Key Up");
}
public void keyTyped(KeyEvent k) { OUTPUT
msg+=k.getKeyChar();
repaint();
}
public void paint(Graphics g){
g.drawString(msg,X,Y);
}
}
Mouse Event

Called just after the user presses a mouse button while the cursor is over
the listened-to component.

Called just after the user releases a mouse button after a mouse press
over the listened-to component

Called just after the user clicks the listened-to component.

Called just after the cursor enters the bounds of the listened-to component.

Called just after the cursor exits the bounds of the listened-to component.
MouseMotionEvent

executed when mouse is dragged over the listened-


to component..

executed when mouse is moved over the


listened-to
component
FocusEvent

This class provide two interface methods:

focusGained:
Called just after the listened-to component gets the
focus.

focusLost:
Called just after the listened-to component Loses the focus.
Example
import java.awt.*;
import java.awt.event.*;
public class FocusListenertest extends Frame
implements FocusListener
{
//initialization occur…
public FocusListenertest()
{
Label l;
add(b1=new Button ("First"),"South");
add(b2=new Button ("Second"),"North");
add(l);
b1.addFocusListener(this)
;
b2.addFocusListener(this)
; setSize(200,200);
Example
}
public void focusGained(FocusEvent fe) {
if(fe.getSource()==b1)
{
l.setText("focus gained of first & Lost of second");
}
public void focusLost(FocusEvent fe) {
if(fe.getSource()==b1)
{
l.setText("focus Lost of First & Gained of Second ");
}
OUTPUT
OUTPUT
WindowEvent Listener

This class provide 8 interface methods:

windowOpened:
Called just after the listened-to window has been shown for
the first time.
windowClosing:
Called in response to a user request for the listened-to
window to be closed.To actually close the window ,the listener
should invoke the windowsdispose or setVisible(fasle) method.
windowClosed:
Called just after the listened-to window has closed.
windowIconified:
Called just after the listened-to window is iconified .
windowDeicoified:
Called just after the listened-to window is deiconified.
WindowEvent Class

• windowActivated and windowDeactivated :


ItemEvent Class

itemStateChanged:
Example
• //where initialization occurs checkbox.addItemListener(this); ...
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{ label.setVisible(true); ... }
else
{ label.setVisible(false);
}}
GRAPHICS PROGRAMMING

The AWT supports a rich assortment of graphics methods.All


graphics are drawn relative to a window.

Coordinates are specified in pixels.


COORDINATE SYSTEMS
 Each pixel can be identified using a two-dimensional
coordinate system
 When referring to a pixel in a Java program, we use a
coordinate system with the origin in the top-left
corner (0, 0) 100 X

40
(100, 40)

Y
DRAWING SHAPES
 A shape can be filled or unfilled, depending on which
method is invoked
 The method parameters specify coordinates and
sizes
 Shapes with curves, like an oval, are usually drawn by
specifying the shape’s bounding rectangle
 An arc can be thought of as a section of an oval
DRAWING A
LINE
10 150 X

20

45

g.drawLine (int startX,int startY,int endX,int endY);

g.drawLine (10, 20, 150, 45);


DRAWING A
RECTANGLE
50 X

20

40

100

g.drawRect (int top,int left,int width,int height);

g.drawRect (50, 20, 100, 40);


DRAWING AN
OVAL
175 X

20

80

bounding
rectangl
Y e 50

g.drawOval (int top,int left,int width,int height);

g.drawOval (175, 20, 50, 80);


DRAWING AN
ARC
175 X

20

80

bounding
rectangl
Y e 50

g.drawArc(int x,int y,int width,int height,int sa,int aa);

g.drawArc (175, 20, 50, 80,0,90);


THE COLOR
CLASS
 Colors in java are in java.awt.Color class

 Class Constructor

 Color(int r, int g , int b)


 Creates an RGB color with specified red,green and
blue values in the range 0 to 255
Object RGB Value

Color.black 0, 0, 0
Color.blue 0, 0, 255
Color.cyan 0, 255, 255
Color.orange 255, 200, 0
Color.white 255, 255, 255
255, 255, 0
Color.yellow
THE COLOR CLASS
METHODS
Method name Meaning
getBlue() gets the blue component
getGreen() gets the green component
getRed() gets the red component
getColor(String) Gets the specified color property
getColor(int) Gets the specified color property of the
color value
getRGB() Gets the RGB value representing the
color in the default RGB color model
FONTS
 The AWT supports multiple type fonts.fonts have family
name,a logical font name, and a face name.
 Fonts are encapsulated by the Font class.
 Font(String name,int fontStyle,int size);

Variable Meaning

String name Name of the font

Float pointsize Size of the font in points

Int size Size of the font in points

Int style Font style


THE FONT
CLASS
Method Description
static Font decode(String str) Returns a font given its name.
boolean equals(Object FontObj) Returns true if the FontObj equals to
current Font otherwise it returns false.
String getFontName() Returns the face name of current font
String getName() Returns the logical name of the font.
int getSize() Returns the size
Int getStyle() returns the style values
boolean isBold() Returns true it the font includes the BOLD
style value, otherwise false.
boolean isItalic Returns true it the font includes the
ITALIC style value, otherwise false.
boolean isPlain Returns true it the font includes the PLAIN
style value, otherwise false.
String toSring() Returns the string equivalent of the
invoking font.
CREATING THE
FONT
 To use new font, we must first construct a Font object that
describes that font.
Font(String fontName,int fontStyle,int size)

fontName ~ name of the font

fontStyle ~ Font.PLAIN, Font.BOLD,


Font.ITALIC.

To combine use pipeline( | ).

 Set the font to current program by calling the method

Void setFont(Font fontObj);


COLOR AND FONT
EXAMPLE
i m p o r tj a v a . a w t . * ;
i m p o r tj a v a . a p p l e t . * ;
p u b l i cc l a s s F o n t D e m o extends Applet {
Font f1;
Color c1,c2;
public voidinit(){
c1=new Color(100,
1 2 0 , 1 0 0 ) ; c 2 = n e wC o l o r
(140,0,0);
f1=new Font(“Arial”,Font.BOLD|Fon
t . I TA L I C , 4 0 ) ; s e t B a c k g r o u n d ( c 1 ) ;
setForeground(c
2); setFont(f1);
Color and Font
example
public void paint(Graphics g) {

g.drawString(“Hello World”,60,40);

OUTPUT
AWT
CONTROLS
 AWT Supports the following types of controls.

Label List

Button Scroll bar

Check box Text box

Check box Text area


Group

Choice list
To add controls you must create an window and add by following method.

Component .add(ComponentObj);

To remove call the following method

void remove(ComponentObj);
LABEL
 A label displays a single line of read only text ,the label
cannot changed by the end user anyway.
Creating the Label

The following constructor used to create the Label


Label();
Label(String text);
Label(String text,int alignment);
the value of alignment must be one of these three
constants : Label.LEFT , Label.RIGHT ,
Label.CENTER.
LABEL
 Set the text of the label by calling
void setText(String str);

 Obtain the current label text by calling


String getText()

 Set the Alignment of the label by calling


Void setAlignment(int align)
 Obtain the current label Alignment by
calling
int getAlignment()
Button
s
This class represents a push-button which displays some specified
text. When a button is pressed, it notifies its Listeners. (More about
Listeners in the next chapter).
To be a Listener for a button, an object must implement the
ActionListener Interface.

Panel aPanel = new Panel();


Button okButton = new Button("Ok");
Button cancelButton = new Button("Cancel");

aPanel.add(okButton));
aPanel.add(cancelButton));

okButton.addActionListene
r(this);
cancelButton.addActionList
ener(this);
Lis
t
This class is a Component which displays a list of
Strings. The list is scrollable, if necessary.
Sometimes called Listbox in other languages.
Lists can be set up to allow single or multiple selections.
The list will return an array indicating which Strings are
selected
List aList = new List();
aList.add("Calgary");
aList.add("Edmonton");
aList.add("Regina");
aList.add("Vancouver");
aList.setMultipleMode(true);
Checkbo
x
This class represents a GUI checkbox with a textual label.
The Checkbox maintains a boolean state indicating whether it
is checked or not.
If a Checkbox is added to a CheckBoxGroup, it will behave like a
radio button.

Checkbox creamCheckbox = new


CheckBox("Cream"); Checkbox sugarCheckbox =
new CheckBox("Sugar");
[
if (creamCheckbox.getState())
{
coffee.addCream();
}
Choic
e
This class represents a dropdown list of Strings.
Similar to a list in terms of functionality, but displayed differently.
Only one item from the list can be selected at one time and the
currently selected element is displayed.

Choice aChoice = new Choice();


aChoice.add("Calgary");
aChoice.add("Edmonton");
aChoice.add("Alert Bay");
[

String selectedDestination=
aChoice.getSelectedItem();
Text
Field
This class displays a single line of optionally editable
text. This class inherits several methods from
TextComponent.
This is one of the most commonly used Components in
the AWT

TextField emailTextField = new TextField();


TextField passwordTextField = new TextField();
passwordTextField.setEchoChar("*");
[…]

String userEmail = emailTextField.getText();


String userpassword =
passwordTextField.getText();
Text Area
This class displays multiple lines of optionally editable
text. This class inherits several methods from
TextComponent.
TextArea also provides the methods: appendText(), insertText() and
replaceText()

// 5 rows, 80 columns
TextArea fullAddressTextArea = new TextArea(5, 80);
[

String userFullAddress=
fullAddressTextArea.getText();
Layout
Managers
Since the Component class defines the setSize() and
setLocation() methods, all Components can be sized and
positioned with those methods.
Problem: the parameters provided to those methods are defined in
terms of pixels. Pixel sizes may be different (depending on the
platform) so the use of those methods tends to produce GUIs
which will not display properly on all platforms.
Solution: Layout Managers. Layout managers are assigned to
Containers. When a Component is added to a Container, its Layout
Manager is consulted in order to determine the size and placement
of the Component.
NOTE: If you use a Layout Manager, you can no longer change
the size and location of a Component through the setSize and
setLocation methods.
Layout Managers
(cont)
There are several different LayoutManagers, each of which sizes and
positions its Components based on an algorithm:
FlowLayout
BorderLayout
GridLayout

For Windows and Frames, the default LayoutManager is


BorderLayout. For Panels, the default LayoutManager is FlowLayout.
Flow
Layout

•The algorithm used by the FlowLayout is to lay out Components


like words on a page: Left to right, top to bottom.
•It fits as many Components into a given row before moving to the next
row.

•Panel aPanel = new Panel();


aPanel.add(new Button("Ok"));
aPanel.add(new Button("Add"));
aPanel.add(new Button("Delete"));
aPanel.add(new Button("Cancel"));
Border
Layout
The BorderLayout Manager breaks the Container up into 5
regions
(North, South, East, West, and Center).
When Components are added, their region is also specified:

Frame aFrame = new Frame();


aFrame.add("North", new Button("Ok"));
aFrame.add("South", new Button("Add"));
aFrame.add("East", new Button("Delete"));
aFrame.add("West", new Button("Cancel"));
aFrame.add("Center", new
Button("Recalculate"));
Border Layout
(cont)
The regions of the BorderLayout are defined as
follows:

North

Wes Center East


t

South
Grid
Layout
The GridLayout class divides the region into a grid of equally sized
rows
and columns.
Components are added left-to-right, top-to-bottom.
The number of rows and columns is specified in the constructor for
the LayoutManager.

Panel aPanel = new Panel();


GridLayout theLayout = new
GridLayout(2,2);
aPanel.setLayout(theLayout);

aPanel.add(new Button("Ok"));
aPanel.add(new Button("Add"));
aPanel.add(new Button("Delete"));
aPanel.add(new
MENU BAR AND
MENU
 A menu bar displays a list of top-level menu choices
 Each choice is associated with a drop-down menu

 This concept is implemented in Java by the following


classes
 MenuBar
 Menu
 MenuItem
MENU BAR AND MENU
(CONT)

 In general, a menu bar contains one or more Menu


objects

 Each Menu object contains a list of MenuItem


objects

 Each MenuItem object represents something that can be


selected by the user
MENUBAR AND MENU
(CONT)
 Following are the constructors for Menu:
 Menu( )
 Menu(String optionName)

 Menu(String optionName, boolean removable)

 Here, optionName specifies the name of the menu


selection
 If removable is true, the pop-up menu can be removed
and allowed to float free
 Otherwise, it will remain attached to the menu bar
MENUBAR AND MENU
(CONT)

 MenuItem defines these constructors


 MenuItem( )
 MenuItem(String itemName)
 MenuItem(String itemName, MenuShortcut keyAccel)
 Here, itemName is the name shown in the menu
 keyAccel is the menu shortcut for this item
SAMPLE PROGRAM
// Illustrate menus.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet
code="MenuDemo"
width=250
height=250>
</applet>
*/
// Create a subclass of Frame
class MenuFrame extends Frame {
String msg = "";
CheckboxMenuItem debug, test;
MenuFrame(String title) {
super(title);
// create menu bar and add it to frame
MenuBar mbar = new MenuBar();
PROGRAM
(CONT.)
// create the menu items
Menu file = new Menu("File");
MenuItem item1, item2, item3, item4, item5;
file.add(item1 = new MenuItem("New..."));
file.add(item2 = new MenuItem("Open..."));
file.add(item3 = new MenuItem("Close"));
file.add(item4 = new MenuItem("-"));
file.add(item5 = new MenuItem("Quit..."));
mbar.add(file);
Menu edit = new Menu("Edit");
MenuItem item6, item7, item8, item9;
edit.add(item6 = new MenuItem("Cut"));
edit.add(item7 = new MenuItem("Copy"));
edit.add(item8 = new MenuItem("Paste"));
edit.add(item9 = new MenuItem("-"));
PROGRAM
(CONT.)
Menu sub = new Menu("Special");
MenuItem item10, item11, item12;
sub.add(item10 = new MenuItem("First"));
sub.add(item11 = new MenuItem("Second"));
sub.add(item12 = new MenuItem("Third"));
edit.add(sub);
// these are checkable menu items
debug = new CheckboxMenuItem("Debug");
edit.add(debug);
test = new CheckboxMenuItem("Testing");
edit.add(test);
mbar.add(edit);
// create an object to handle action and item events
MyMenuHandler handler = new MyMenuHandler(this);
PROGRAM (CONT.)
// register it to receive those events
item1.addActionListener(handler);
item2.addActionListener(handler);
item3.addActionListener(handler);
item4.addActionListener(handler);
item5.addActionListener(handler);
item6.addActionListener(handler);
item7.addActionListener(handler);
item8.addActionListener(handler);
item9.addActionListener(handler);
item10.addActionListener(handler);
item11.addActionListener(handler);

item12.addActionListener(handler);
debug.addItemListener(handler);
test.addItemListener(handler);
PROGRAM
(CONT.)
// create an object to handle window events
MyWindowAdapter adapter = new MyWindowAdapter(this);
// register it to receive those events
addWindowListener(adapter);
}
public void paint(Graphics g)
{ g.drawString(msg, 10, 200);
if(debug.getState())
g.drawString("Debug is on.", 10, 220);
else
g.drawString("Debug is off.", 10, 220);
if(test.getState())
g.drawString("Testing is on.", 10, 240);
else
g.drawString("Testing is off.", 10,
240);
}
}
PROGRAM
(CONT.)
class MyWindowAdapter extends WindowAdapter {
MenuFrame menuFrame;
public MyWindowAdapter(MenuFrame menuFrame) {
this.menuFrame = menuFrame;
}
public void windowClosing(WindowEvent we) {
menuFrame.setVisible(false);
}
}
class MyMenuHandler implements ActionListener, ItemListener {
MenuFrame menuFrame;
public MyMenuHandler(MenuFrame menuFrame) {
this.menuFrame = menuFrame;
}
PROGRAM
(CONT.)
// Handle action events
public void actionPerformed(ActionEvent ae) {
String msg = "You selected ";
String arg = (String)ae.getActionCommand();
if(arg.equals("New..."))
msg += "New.";
else if(arg.equals("Open..."))
msg += "Open.";
else if(arg.equals("Close"))
msg += "Close.";
else if(arg.equals("Quit..."))
msg += "Quit.";
else if(arg.equals("Edit"))
msg += "Edit.";
else if(arg.equals("Cut"))
msg += "Cut.";
else if(arg.equals("Copy"))
msg += "Copy.";
PROGRAM
(CONT.)
else if(arg.equals("Paste"))
msg += "Paste.";
else if(arg.equals("First"))
msg += "First.";
else if(arg.equals("Second"))
msg += "Second.";
else if(arg.equals("Third"))
msg += "Third.";
else if(arg.equals("Debug"))
msg += "Debug.";
else if(arg.equals("Testing"))
msg += "Testing.";
menuFrame.msg = msg;
menuFrame.repaint();
}
PROGRAM
(CONT.)
// Handle item events
public void itemStateChanged(ItemEvent ie) {
menuFrame.repaint();
}
}
// Create frame window.
public class MenuDemo extends Applet {
Frame f;
public void init() {
f = new MenuFrame("Menu Demo");
int width = Integer.parseInt(getParameter("width"));
int height = Integer.parseInt(getParameter("height"));
setSize(new Dimension(width, height));
f.setSize(width, height);
f.setVisible(true);
}
PROGRAM
(CONT.)
public void start() {
f.setVisible(true);
}
public void stop() {
f.setVisible(false);
}
}

Sam
ple
out
put
is
sho
wn
her
e

Fig. 74.1 Output of MenuDemo


THANK YOU

You might also like