Please enable JavaScript.
Coggle requires JavaScript to display documents.
CHAPTER 1 -GRAPHICAL USER INTERFACE(GUI) (1.2 FRAME WINDOWS AND MENUBARS…
CHAPTER 1 -GRAPHICAL USER INTERFACE(GUI)
1.1 UNDERSTAND AWT FUNDAMENTAL
Abstract Window Toolkit(AWT)
-AWT is a package (java.awt) that contains classes to built graphical user interface.
AWT & Swing Relationship
-Swing is a recent set of GUI interface.
-Swing extend the AWT that the programmer can create generalized GUI object that are independent of a specific operating system's windowing system
Package of AWT
-The Java.AWT package provides classes for AWT API such as:
1)Text Field
2)Label
3)TextArea
4)RadioButton
5)CheckBox
6)Choice
7)List
Features of AWT
1)Platform-dependent
2)Heavyweight
AWT Hieracachy
1)Container
2)Panel
3)Window
4)Frame
5)Dialog
6)Applet
Method of Component Class
1)public void add (component c)
2)public void setSize(int width,int height)
3)public void setLayout(LayoutManager m)
4)public void setVisible(boolean status)
1.2 FRAME WINDOWS AND MENUBARS
MENU BAR
MENU COMPONENT
• MenuItem
• Menu
WRITE A PANEL (STEP BY STEP)
Create Frame
Frame mainFrame = new Frame("Java AWT Examples");
Set layout for Frame
mainFrame.setLayout(new GridLayout(3, 1));
Create Panel
controlPanel = new Panel();
Set layout for Panel
controlPanel.setLayout(new FlowLayout());
Add Panel to Frame
mainFrame.add(controlPanel);
DEFINE THE USE OF FRAME IN JAVA PROGRAM
Frame is the basis to contain other user interface components in JAVA graphical applications
METHOD
setDefaultCloseOperation()
setSize()
setVisible()
setLocation(x,y)
FRAME LOCATION
setLocation(x, y) method
setBounds(x, y, width, height).
AWT COMPONENTS
Component
• Canvas
• Scrollbar
• Button
• Checkbox
• Label
• List
• Choice
• TextComponent
• TextArea
• TextField
CREATE AWT BUTTON
Button hw = new Button("Hello World!");
add(hw);
CREATE AWT LABEL
Label label1 = new Label();
label1.setText("Label1");
CREATE AWT CHECKBOX
CheckboxGroup cbg = new CheckboxGroup();
Checkbox cb1 = new Checkbox("American
Express",cbg,false);
CREATE AWT CHOICE
Choice choice = new Choice();
choice.add("ichi");
add(choice);
CREATE AWT TEXTFIELD
AND TEXTAREA
TextField textField = new TextField(20);
TextArea textArea = new TextArea(5, 20);
CREATE AWT LISTS
List l = new List(2, true); //prefer 2 items visible
l.add("zero");
l.add("uno");
add(l);
CREATE AWT MENUS
MenuBar mb = new MenuBar();
setMenuBar(mb);