Please enable JavaScript.
Coggle requires JavaScript to display documents.
CHAPTER 1 GRAPHICAL USER INTERFACE (1.2 Frame Windows and Menu Bars (A…
CHAPTER 1 GRAPHICAL USER INTERFACE
1.2 Frame Windows and Menu Bars
THE METHODS
setDefaultCloseOperation()
setSize()
setVisible()
setLocation(x,y)
Syntax
Frame f = new TestFrame("TestFrame");
Frame Location
setLocation(x, y) method in the JFrame class or
setBounds(x, y, width, height)
FRAME
Menu Bars
MenuBar - container for menu and manages menu bar (Classes
used to define menu)
A Menu Bar displays a list of top-level menu choices
Create Menu Bar in Java Programs
//display fileMenu.add(newAction);
fileMenu.add(openAction);
fileMenu.add(exitAction);
// Create and add simple menu item to one of the drop down menuMenuItem newAction = new MenuItem("New");MenuItem openAction = new MenuItem("Open");MenuItem exitAction = new MenuItem("Exit");
// Define and add two drop down menu to the menubarMenu fileMenu = new Menu("File");
Menu editMenu = new Menu("Edit");menuBar.add(fileMenu);menuBar.add(editMenu);
MenuBar menuBar = new MenuBar();// Add the menubar to the frame setMenuBar(menuBar);
This concept is implemented in Java by the following classes
• MenuBar
• Menu
• MenuItem
A PROGRAM WITH
DIALOGS AND PANELS
Panels act as smaller containers for grouping user
interface components. User interface components in panels and place the panels in a frame.
WRITE A PANEL (STEP BY
STEP)
1.Create Frame
Frame mainFrame = new Frame("Java AWT Examples");
2.. Set layout for Frame
mainFrame.setLayout(new GridLayout(3, 1));
3.Create Panel
controlPanel = new Panel();
Set layout for Panel
controlPanel.setLayout(new FlowLayout());
Add Panel to Frame
mainFrame.add(controlPanel);
AWT COMPONENTS
Component
Button
Checkbox
Label
List
Choice
TextComponent
TextArea
TextField
SET COLOR AND FONTS IN
JAVA
Font font = new Font("Arial", Font.BOLD, 20);
label1.setFont(font);
label1.setbackground(Color.BLUE);
add(label1);
1.1 ABSTRACT WINDOW TOOLKIT (AWT)
Abstract Window Toolkit is a PACKAGE (java.awt) that contain classes to built Graphical User (GUI)
FEATURES OF AWT
Platform-dependent
components are displayed according to the view of operating system.
Heavyweight
its components uses the resources of system.
AWT HIERARCHY
Container
Container is an abstract subclass of Component, which allows other components to be nested inside it.
Panel
A Panel is a simplest Container whose primary purpose is to subdivide the drawing area into separate rectangular pieces.
Window
A Window object is a top-level window. It does not have borders and menubar.
Frame
A Frame is a top-level window with a title and a
border.
two ways to create a Frame
By Instantiating Frame class
By extending Frame class
Dialog
It can be moved but often can't be resized .Its purpose is to get some particular information from the user (input) or to impart some particularly important information to the user (output) .
Applet
Applet is any small application that performs one specific task that runs within the scope of a larger program, often as a plug-in.
METHOD OF COMPONENT CLASS
public void add(Component c)
public void setSize(int width,int height)
public void setLayout(LayoutManager m)
public void setVisible(boolean status)