0% found this document useful (0 votes)
2 views

Chap_01_Abstract Windowing Toolkit(modify)

This document introduces the Abstract Window Toolkit (AWT) in Java, detailing its components, hierarchy, and structure for creating graphical user interfaces (GUIs). It covers various AWT classes such as Component, Container, and specific controls like Buttons, Checkboxes, and TextFields, along with their constructors and methods. Additionally, it provides examples of creating windowed programs and applets using AWT components.

Uploaded by

dikshabhandare43
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chap_01_Abstract Windowing Toolkit(modify)

This document introduces the Abstract Window Toolkit (AWT) in Java, detailing its components, hierarchy, and structure for creating graphical user interfaces (GUIs). It covers various AWT classes such as Component, Container, and specific controls like Buttons, Checkboxes, and TextFields, along with their constructors and methods. Additionally, it provides examples of creating windowed programs and applets using AWT components.

Uploaded by

dikshabhandare43
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 78

ADVANCE JAVA PROGRAMMING

CHAPTER 01

ABSTRACT WINDOWING TOOLKIT


The Objectives Of This Section Are:

To Introduce AWT
To discuss the classes present in the java.awt package
To understand the hierarchy of the AWT
To outline the basic structure of GUIs
To show how to add components to containers
To understand how to use Layout Managers
INTRODUCTION OF AWT

 Awt stands for Abstract window Toolkit.


 Awt is used to develop graphical user interface or window based components.
 The Awt is collection of classes which is present in the awt package.
 Awt component are platform independent as well as heavy weight.
 The Awt package contains large number of classes which help to include various
graphical component.
 The graphical components include textbox,buttons,label,radio button and so on.
AWT (Abstract Windowing Toolkit)

The AWT is roughly broken into three categories


Components
Layout Managers
Graphics
Many AWT components have been replaced by Swing components
It is generally not considered a good idea to mix Swing components and
AWT components. Choose to use one or the other.
1.1 Component, Container, Window, Frame, Panel
AWT ass Hierarchy
Component
Container Window Frame
Button Panel
List
Checkbox
Note: There are more classes, however,
Choice
these are what are covered in this section
Label
TextComponent TextField
TextArea
Component
Component is the superclass of most of the displayable classes
defined within the AWT. Note: it is abstract.
MenuComponent is another class which is similar to Component
except it is the superclass for all GUI items which can be displayed
within a drop-down menu.
The Component class defines data and methods which are relevant to
all Components.
Container
Container is a subclass of Component. (ie. All containers are
themselves, Components)
Containers contain components
For a component to be placed on the screen, it must be placed
within a Container.
The Container class defined all the data and methods necessary
for managing groups of Components
Containers And Components
 The job of a Container is to hold and display Components

 Some common subclasses of Component are Button, Checkbox, Label,


Scrollbar, TextField, and TextArea

 A Container is also a Component


 This allows Containers to be nested
 Some Container subclasses are Panel (and Applet), Window, and Frame

9
Some Types Of Components
Button Checkbox
Label

Choice Scrollbar

TextField List TextArea

Button

Checkbox
CheckboxGroup
10
Windows and Frames

The Window class defines a top-level Window with no Borders or Menu bar.
Usually used for application splash screens
Frame defines a top-level Window with Borders and a Menu Bar
Frames are more commonly used than Windows
Once defined, a Frame is a Container which can contain Components
Panels
When writing a GUI application, the GUI portion can become
quite complex.
To manage the complexity, GUIs are broken down into groups of
components. Each group generally provides a unit of
functionality.
A Panel is a rectangular Container whose sole purpose is to hold
and manage components within a GUI.
Container & Components Together for GUI

Container (Applet)
Containers (Panels)

Component
(Canvas)
Components
(Buttons)
Components (TextFields)
Components (Labels)
1.2 Creating Windowed Program And Applet
Download JDK 8

URL to download JDK 8


Java Downloads | Oracle

Note:- Latest Version of JDK is JDK 17 ,but it is not possible to test your applet program with
appletviewer tool because this tool is not present with later version of jdk, above 8 so we download
and use JDK 8
Install And Run 1st Program With Applet
Creating Windowed Program with Applet
import java.awt.*;
import java.applet.*;
public class sampleApplet extends Applet
{
public void init()
{ Frame ob=new Frame();
ob.setSize(200,200);
ob.setTitle("Frame Program");
ob.setVisible(true);
}
public void paint(Graphics g)
{ g.drawString("Inside Applet",20,10);
}
} /* <applet code="sampleApplet" width=200 height=300></applet> */
1.3 AWT Controls And Managers:
use Of
Labels,
Buttons,
checkbox,
checkboxGroup,
scrollBars,
TextField,
TextArea,
List,
Adding Control on Applet window.
Java AWT Label

The object of the Label class is a component for placing text in a


container. It is used to display a single line of read only text. The
text can be changed by a programmer but a user cannot edit it
directly.
It is called a passive control as it does not create any event when it
is accessed. To create a label, we need to create the object
of Label class.
Label class Constructors
Sr. no. Constructor Description
1. Label() It constructs an empty label.

2. Label(String text) It constructs a label with the given


string (left justified by default).

3. Label(String text, int alignement) It constructs a label with the specified


string and the specified alignment.
Alignment Values:
Label.LEFT
Label.RIGHT
Label.CENTER
Label Class Methods

Sr.no. Method name Description


1. void setText(String text) It sets the texts for label with the
specified text.
2. void setAlignment(int alignment) It sets the alignment for label with the
specified alignment.
3. String getText() It gets the text of the label
4. int getAlignment() It gets the current alignment of the
label.
Example 1.// creating the object of Frame class and Label cla
ss
2. Frame f = new Frame ("Label example");
3. Label l1, l2;
4.
5. // initializing the labels
6. l1 = new Label ("First Label.");
7. l2 = new Label ("Second Label.");
8.
9. // set the location of label
10. l1.setBounds(50, 100, 100, 30);
11. l2.setBounds(50, 150, 100, 30);
12.
13. // adding labels to the frame
14. f.add(l1);
Java AWT Button

A button is basically a control component with a label that generates an


event when pushed. The Button class is used to create a labeled button
that has platform independent implementation. The application result in
some action when the button is pushed.
Button Class Constructors

Sr. no. Constructor Description


1. Button( ) It constructs a new button with an empty
string i.e. it has no label.
2. Button (String text) It constructs a new button with given string
as its label.
Button Class Methods

Sr. no. Method Description


1. void setText (String text) It sets the string message on the button

2. String getText() It fetches the String message on the button.

3. void setLabel (String It sets the label of button with the specified
label) string.
4. String getLabel() It fetches the label of the button.
Example

1. // create instance of frame with the label


2. Frame f = new Frame("Button Example");

3. // create instance of button with label


4. Button b = new Button("Click Here");

5. // set the position for the button in frame


6. b.setBounds(50,100,80,30);

7. // add button to the frame


8. f.add(b);
Java AWT Checkbox

The Checkbox class is used to create a checkbox. It is used to


turn an option on (true) or off (false). Clicking on a Checkbox
changes its state from "on" to "off" or from "off" to "on".
Checkbox Class Constructors

Sr Constructor Description
1. Checkbox() It constructs a checkbox with no string as the label.
2. Checkbox(String label) It constructs a checkbox with the given label.
3. Checkbox(String label, It constructs a checkbox with the given label and
boolean state) sets the given state.
4. Checkbox(String label, It constructs a checkbox with the given label, set
boolean state, the given state in the specified checkbox group.
CheckboxGroup group)
5. Checkbox(String label, It constructs a checkbox with the given label, in the
CheckboxGroup group, given checkbox group and set to the specified state.
boolean state)
Checkbox Class Methods

Sr. Method name Description


no.
1. String getLabel() It fetched the label of checkbox.
2. boolean getState() It returns true if the checkbox is on, else
returns off.
3. void setLabel(String label) It sets the checkbox's label to the string
argument.
4. void setState(boolean It sets the state of checkbox to the specified
state) state.
Example
1.// creating the frame with the title
2. Frame f = new Frame("Checkbox Example");
3.// creating the checkboxes
4. Checkbox checkbox1 = new Checkbox("C++");
5. checkbox1.setBounds(100, 100, 50, 50);
6. Checkbox checkbox2 = new Checkbox("Java", true);
7.// setting location of checkbox in frame
8. checkbox2.setBounds(100, 150, 50, 50);
9.// adding checkboxes to frame
10. f.add(checkbox1);
11. f.add(checkbox2);
Java AWT Checkboxgroup

The object of CheckboxGroup class is used to group together a set


of Checkbox. At a time only one check box button is allowed to be in
"on" state and remaining check box button in "off" state. It inherits
the object class.
AWT CheckboxGroup Class Declaration
Sr Constructor Description
1. CheckboxGroup() It constructs a checkboxgroup object with the given
label, set the given state in the specified checkbox
group.
AWT Checkbox Class Declaration
Sr Constructor Description
1. Checkbox(String label, It constructs a checkbox with the given label, set
boolean state, the given state in the specified checkbox group.
CheckboxGroup group)
2. Checkbox(String label, It constructs a checkbox with the given label, in the
CheckboxGroup group, given checkbox group and set to the specified state.
boolean state)
Example

1. Frame f= new Frame("CheckboxGroup Example");


2. CheckboxGroup cbg = new CheckboxGroup();
3. Checkbox checkBox1 = new Checkbox("C++", cbg, false);
4. checkBox1.setBounds(100,100, 50,50);
5. Checkbox checkBox2 = new Checkbox("Java", cbg, true);
6. checkBox2.setBounds(100,150, 50,50);
7. f.add(checkBox1);
8. f.add(checkBox2);
Java AWT Scrollbar

The object of Scrollbar class is used to add horizontal and vertical


scrollbar. Scrollbar is a GUI component allows us to see invisible number
of rows and columns.
It can be added to top-level container like Frame or a component like
Panel. The Scrollbar class extends the Component class.
Scrollbar Class Constructors
Sr Constructor Description
1 Scrollbar() Constructs a new vertical scroll bar.
2 Scrollbar(int orientation) Constructs a new scroll bar with the specified
orientation.
Orientation:
static int HORIZONTAL - It is a constant to
indicate a horizontal scroll bar.
static int VERTICAL - It is a constant to indicate
a vertical scroll bar.
3 Scrollbar(int orientation, Constructs a new scroll bar with the specified
int value, int visible, int orientation, initial value, visible amount, and
minimum, int maximum) minimum and maximum values.
Scrollbar
Scrollbar Class Methods
Sr Method name Description
.
1 void addNotify() It creates the peer of scroll bar.
2 int getBlockIncrement() It gets the block increment of the scroll bar.
3 int getMaximum() It gets the maximum value of the scroll bar.
4 int getMinimum() It gets the minimum value of the scroll bar.
5 int getOrientation() It returns the orientation of scroll bar.
6 int getUnitIncrement() It fetches the unit increment of the scroll bar.
7 int getValue() It fetches the current value of scroll bar.
8 int getVisibleAmount() It fetches the visible amount of scroll bar.
Example

1.// creating a frame


2. Frame f = new Frame("Scrollbar Example");
3. // creating a scroll bar
4. Scrollbar s = new Scrollbar();
5.
6. // setting the position of scroll bar
7. s.setBounds (100, 100, 50, 100);
8.
9. // adding scroll bar to the frame
10. f.add(s);
Java AWT Textfield

The object of a TextField class is a text component that allows a


user to enter a single line text and edit it. It
inherits TextComponent class, which further
inherits Component class.
Textfield Class Constructors

Sr. no. Constructor Description


1. TextField() It constructs a new text field component.
2. TextField(String text) It constructs a new text field initialized with
the given string text to be displayed.
3. TextField(int columns) It constructs a new textfield (empty) with
given number of columns.
4. TextField(String text, It constructs a new text field with the given
int columns) text and given number of columns (width).
TextField Class Methods
Sr. Method name Description
no.
1 int getColumns() It fetches the number of columns in text
field.
2 char getEchoChar() It fetches the character that is used for
echoing.
3 Dimension getPreferredSize() It fetches the preferred size of the text
field.
4 Dimension It fetches the preferred size of the text
getPreferredSize(int columns) field with specified number of columns.
5 void setColumns(int columns) It sets the number of columns in text field.
6 void setEchoChar(char c) It sets the echo character for text field.
7 void setText(String t) It sets the text presented by this text
Example

1. // creating a frame
2. Frame f = new Frame("TextField Example");
3. // creating objects of textfield
4. TextField t1, t2;
5. // instantiating the textfield objects
6. // setting the location of those objects in the frame
7. t1 = new TextField("Welcome to Javatpoint.");
8. t1.setBounds(50, 100, 200, 30);
9. t2 = new TextField("AWT Tutorial");
10. t2.setBounds(50, 150, 200, 30);
11. // adding the components to frame
12. f.add(t1);
13. f.add(t2);
Java AWT Textarea

The object of a TextArea class is a multiline region that displays text. It


allows the editing of multiple line text. It inherits TextComponent class.
The text area allows us to type as much text as we want. When the text in
the text area becomes larger than the viewable area, the scroll bar appears
automatically which helps us to scroll the text up and down, or right and
left.
Class constructors:
Sr. Constructor Description
no.
1. TextArea() It constructs a new and empty text area with no text in it.
2. TextArea (int It constructs a new text area with specified number of
row, int column) rows and columns and empty string as text.
3. TextArea (String It constructs a new text area and displays the specified
text) text in it.
4. TextArea (String It constructs a new text area with the specified text in the
text, int row, int text area and specified number of rows and columns.
column)
Class constructors:
Sr. Constructor Description
no.
5. TextArea (String text, int It construcs new text area with specified text in
row, int column, int text area and specified number of rows and
scrollbars) columns and visibility.

•static int SCROLLBARS_BOTH -


It creates and displays both horizontal and vertical scrollbars.
•static int SCROLLBARS_HORIZONTAL_ONLY -
It creates and displays only the horizontal scrollbar.
•static int SCROLLBARS_VERTICAL_ONLY -
It creates and displays only the vertical scrollbar.
•static int SCROLLBARS_NONE -
It doesn't create or display any scrollbar in the text area.
TextArea Class Methods

Sr. Method name Description


no.
1 void append(String str) It appends the specified text to the current text of
text area.
2 int getColumns() It returns the number of columns of text area.
3 Dimension getPreferredSize() It determines the preferred size of a text area.
4 Dimension preferredSize(int It determines the preferred size of a text area with
rows, int columns) given number of rows and columns.
5 int getRows() It returns the number of rows of text area.
6 void setColumns(int columns) It sets the number of columns for this text area.
7 void setRows(int rows) It sets the number of rows for this text area.
Example

1.// creating a frame


2. Frame f = new Frame();
3.// creating a text area
4. TextArea area = new TextArea("Welcome to javatpoint");
5.// setting location of text area in frame
6. area.setBounds(10, 30, 300, 300);
7.// adding text area to frame
8. f.add(area);
Java AWT List

 The List Class provides a compact,multiple-choice,scrolling selection


list.Unlike the Choice object, which shows only the single selected items in the
menu,a list object can be constructed to show any number of choices in the
visible window .It can also be created to allow multiple selections.
List Class Constructors

Sr. Constructor Description


no.

1. List() It creates a list control that allow only one item to be


selected at any one time.
2. List(int numRows) The number of entries in the list that will be visible.
3. List(int If multiSelect is true,then the user may select two or
numRows,Boolean more items at a time,If it is false,then only one item may
multipleSelect) be selected.
List Class Methods
Sr. Methods Description
No.
1. Void add(String name) It adds items to the end of the List.
2. Void add(String name,int index) It adds the item at the index specified by
index.Indexing begins by Zero.We can specify -1 to
add the item to the end of the List.
3. String getSelectedItem() It returns a string containing the name of item.If
more than one item is selected or if no selection has
yet been made,null is returned.
4. Int getSelectedIndex() It returns the index of the item.The first item is at
index 0.If more than one item is selected,or if no
selection has yet been made,-1 is returned.
List Class Methods
Sr. Methods Description
No.
5. String [] It Returns an array containg the names of the
getSelectedItems() currently Selected items.
6. int[] getSelectedIndexes() It Returns an array containg the indexes of the
currently Selected items.
7. Int getItemCount() It obtain the number of items in the list.
8. String getItem(int index) It specifies the index of the desired item
Example

1. // creating a frame
2. Frame f = new Frame(List Example);
3. // creating a text area
4. List l1 = new List(“summer");
5. // setting location of text area in frame
6. area.setBounds(10, 30, 300, 300);
7. // adding text area to frame
8. f.add(area);
1.4 Use of Layout Managers:
FlowLayout
BorderLayout
GridLayout
CardLayout
GridbagLayout
MenuBars
Menus
DialogBoxes
FileDialog
JAVA LAYOUTMANAGERS

The LayoutManagers are used to arrange components in a particular


manner. The Java LayoutManagers facilitates us to control the positioning
and size of the components in GUI forms. LayoutManager is an interface
that is implemented by all the classes of layout managers. There are the
following classes that represent the layout managers:
1.java.awt.BorderLayout
2.java.awt.FlowLayout
3.java.awt.GridLayout
4.java.awt.CardLayout
5.java.awt.GridBagLayout
JAVA BORDER LAYOUT

The BorderLayout is used to arrange the components in five regions:


north, south, east, west, and center. Each region (area) may contain one
component only. It is the default layout of a frame or window. The
BorderLayout provides five constants for each region:
1.public static final int NORTH
2.public static final int SOUTH
3.public static final int EAST
4.public static final int WEST
5.public static final int CENTER
CONSTRUCTORS OF BORDERLAYOUT CLASS

•BorderLayout(): creates a border layout but with no gaps between the


components.
•BorderLayout(int hgap, int vgap): creates a border layout with the
given horizontal and vertical gaps between the components.
FLOWLAYOUT

It arranges the components in a container like the words on a page. It fills the
top line from left to right and top to bottom. The components are arranged
in the order as they are added i.e. first components appears at top left, if the
container is not wide enough to display all the components, it is wrapped
around the line. Vertical and horizontal gap between components can be
controlled. The components can be left, center or right aligned.

Fields of FlowLayout class


1.public static final int LEFT
2.public static final int RIGHT
3.public static final int CENTER
CONSTRUCTORS OF FLOWLAYOUT CLASS

1.FlowLayout(): creates a flow layout with centered alignment and a default


5 unit horizontal and vertical gap.
2.FlowLayout(int align): creates a flow layout with the given alignment and
a default 5 unit horizontal and vertical gap.
3.FlowLayout(int align, int hgap, int vgap): creates a flow layout with the
given alignment and the given horizontal and vertical gap.
JAVA GRID LAYOUT
The Java GridLayout class is used to arrange the components in a rectangular
grid. One component is displayed in each rectangle.
Constructors of GridLayout class
1.GridLayout(): creates a grid layout with one column per component in a
row.
2.GridLayout(int rows, int columns): creates a grid layout with the given
rows and columns but no gaps between the components.
3.GridLayout(int rows, int columns, int hgap, int vgap): creates a grid
layout with the given rows and columns along with given horizontal and
vertical gaps.
1 2 3
4 5 6
7 8 9
JAVA CARD LAYOUT
The Java CardLayout class manages the components in such a manner that
only one component is visible at a time. It treats each component as a card that is
why it is known as CardLayout.
Constructors of CardLayout Class
1.CardLayout(): creates a card layout with zero horizontal and vertical gap.
2.CardLayout(int hgap, int vgap): creates a card layout with the given
horizontal and vertical gap.
COMMONLY USED METHODS OF CARD LAYOUT CLASS

•public void next(Container parent): is used to flip to the next card of the
given container.
•public void previous(Container parent): is used to flip to the previous card
of the given container.
•public void first(Container parent): is used to flip to the first card of the
given container.
•public void last(Container parent): is used to flip to the last card of the given
container.
•public void show(Container parent, String name): is used to flip to the
specified card with the given name.
JAVA GRIDBAG LAYOUT
The Java GridBagLayout class is used to align components vertically,
horizontally or along their baseline.
The components may not be of the same size. Each GridBagLayout object
maintains a dynamic, rectangular grid of cells. Each component occupies one or
more cells known as its display area. Each component associates an instance of
GridBagConstraints. With the help of the constraints object, we arrange the
component's display area on the grid. The GridBagLayout manages each
component's minimum and preferred sizes in order to determine the
component's size. GridBagLayout components are also arranged in the
rectangular grid but can have many different sizes and can occupy multiple
rows or columns.
Constructor
GridBagLayout(): The parameterless constructor is used to create a grid bag layout
manager.
Specifying Constraints
The following code is typical of what goes in a container that uses a GridBagLayout. You will
see a more detailed example in the next section.

Panel pane = new Panel(new GridBagLayout());


GridBagConstraints c = new GridBagConstraints();
//For each component to be added to this container:
//...Create the component... //...Set instance variables in the GridBagConstraints instance...

pane.add(theComponent, c);

As you might have guessed from the above example, it is possible to reuse the
same GridBagConstraints instance for multiple components, even if the components have
different constraints. However, it is recommended that you do not reuse GridBagConstraints, as
this can very easily lead to you introducing subtle bugs if you forget to reset the fields for each
new instance.
gridx, gridy

Specify the row and column at the upper left of the component. The leftmost
column has address gridx=0 and the top row has address gridy=0.
Use GridBagConstraints.RELATIVE (the default value) to specify that the
component be placed just to the right of (for gridx) or just below (for gridy)
the component that was added to the container just before this component was
added. We recommend specifying the gridx and gridy values for each
component rather than just using GridBagConstraints.RELATIVE; this tends
to result in more predictable layouts.
gridwidth, gridheight
Specify the number of columns (for gridwidth) or rows (for gridheight) in the
component's display area. These constraints specify the number of cells the component
uses, not the number of pixels it uses. The default value is 1.
Use GridBagConstraints.REMAINDER to specify that the component be the last one in
its row (for gridwidth) or column (for gridheight).
Use GridBagConstraints.RELATIVE to specify that the component be the next to last
one in its row (for gridwidth) or column (for gridheight). We recommend specifying
the gridwidth and gridheight values for each component rather than just
using GridBagConstraints.RELATIVE and GridBagConstraints.REMAINDER; this
tends to result in more predictable layouts.
fill
Used when the component's display area is larger than the component's
requested size to determine whether and how to resize the component.
Valid values (defined as GridBagConstraints constants)
include NONE (the default), HORIZONTAL (make the component wide
enough to fill its display area horizontally, but do not change its
height), VERTICAL (make the component tall enough to fill its display
area vertically, but do not change its width), and BOTH (make the
component fill its display area entirely).
ipadx, ipady
Specifies the internal padding: how much to add to the size of the component.
The default value is zero. The width of the component will be at least its
minimum width plus ipadx*2 pixels, since the padding applies to both sides of
the component. Similarly, the height of the component will be at least its
minimum height plus ipady*2 pixels.

insets
Specifies the external padding of the component -- the minimum amount of space
between the component and the edges of its display area. The value is specified
as an Insets object. By default, each component has no external padding.
IPADX,IPADY AND INSETS
anchor
Used when the component is smaller than its display area to determine where
(within the area) to place the component. Valid values (defined
as GridBagConstraints constants) are CENTER (the
default), PAGE_START, PAGE_END, LINE_START, LINE_END, FIRST_
LINE_START, FIRST_LINE_END, LAST_LINE_END,
and LAST_LINE_START.
Here is a picture of how these values are interpreted in a container that has the
default, left-to-right component orientation.
FIRST_LINE_START PAGE_START FIRST_LINE_END

LINE_START CENTER LINE_END

LAST_LINE_START PAGE_END LAST_LINE_END

Version note: The PAGE_* and *LINE_* constants were introduced in 1.4. Previous releases require values named after points of the
compass. For example, NORTHEAST indicates the top-right part of the display area. We recommend that you use the new constants, instead,
since they enable easier localization.
weightx, weighty
Specifying weights is an art that can have a significant impact on the appearance of the
components a GridBagLayout controls. Weights are used to determine how to distribute
space among columns (weightx) and among rows (weighty); this is important for
specifying resizing behavior.
Unless you specify at least one non-zero value for weightx or weighty, all the components
clump together in the center of their container. This is because when the weight is 0.0
(the default), the GridBagLayout puts any extra space between its grid of cells and the
edges of the container.
Generally weights are specified with 0.0 and 1.0 as the extremes: the numbers in between are
used as necessary. Larger numbers indicate that the component's row or column should
get more space. For each column, the weight is related to the highest weightx specified
for a component within that column, with each multicolumn component's weight being
split somehow between the columns the component is in. Similarly, each row's weight is
related to the highest weighty specified for a component within that row. Extra space
tends to go toward the rightmost column and bottom row.
WEIGHTX AND WEIGHTY
MENU, MENUITEMS AND MENUBAR CLASS

•A menu bar can be created using MenuBar class.


•A menu bar may contain one or multiple menus, and these menus are
created using Menu class.
•A menu may contain one of multiple menu items and these menu items
are created using MenuItem class.
CONSTRUCTORS OF MENUBAR, MENU AND MENUITEM

Constructor Description
Creates a menu bar to which one or many menus
public MenuBar()
are added.
Creates a menu with a title.
public Menu(String title)
public MenuItem(String title) Creates a menu item with a title.
JAVA AWT DIALOG

The Dialog control represents a top level window with a border and a
title used to take some form of input from the user. It inherits the
Window class.

Unlike Frame, it doesn't have maximize and minimize buttons.

Frame vs Dialog

Frame and Dialog both inherits Window class. Frame has maximize
and minimize buttons but Dialog doesn't have.
FILEDIALOG BOX
FileDialog control represents a dialog window from which the user can select a file.

Class declaration
Following is the declaration for java.awt.FileDialog class:
public class FileDialog extends Dialog

Field

•static int LOAD -- This constant value indicates that the purpose of the file dialog
window is to locate a file from which to read.
•static int SAVE -- This constant value indicates that the purpose of the file dialog
window is to locate a file to which to write.
S.N. Constructor & Description
1 FileDialog(Frame parent)
Creates a file dialog for loading a file.
2 FileDialog(Frame parent, String title)
Creates a file dialog window with the specified title for loading a
file.
3 FileDialog(Frame parent, String title, int mode)
Creates a file dialog window with the specified title for loading or
saving a file.
S.N. Method & Description
1 String getDirectory()
Gets the directory of this file dialog.
2 String getFile()
Gets the selected file of this file dialog.
3 FilenameFilter getFilenameFilter()
Determines this file dialog's filename filter.
4 int getMode()
Indicates whether this file dialog box is for loading from a file or for
saving to a file.
5 void setDirectory(String dir)
Sets the directory of this file dialog window to be the specified directory.
6 void setFile(String file)
Sets the selected file for this file dialog window to be the specified file.
7 void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified filter.
8 void setMode(int mode)
Sets the mode of the file dialog.

You might also like