GUI(Building a Simple User Interface)
• Using to create graphical applications. two main groups of classes (libraries) that are used for creating windows in Java: – AWT (AbstractWindow Toolkit )• available for working with graphics. This library is a
simple set of classes like Button, TextField, Label and others.
– Swing• JButton, JTextField, JLabel, and so on.
AWT Controls, Layout Managers, and Menus
• Control Fundamentals– Labels– Push buttons– Check boxes– Choice lists– Lists– Scroll bars– Text editing
Layout
• Layout Manager• Set Bound កូអរដោ�ដោ�
Layout Manager• Flow Layout
• Grid Layout
• Border Layout
• Card Layout
AWT(Abstract Window Toolkit)
• A graphical user interface is built of graphical elements called components(such items as buttons, scrollbars, and text fields … ).
• Components do not stand alone, but rather are found within containers.
• Container control Layout
Component tree
Types of components
Type of container
WindowA top-level display surface (a window). An instance of the Window class is not attached to nor embedded within another container. An instance of the Window class has no border and no title.
FrameA top-level display surface (a window) with a border and title. An instance of the Frame class may have a menu bar. It is otherwise very much like an instance of the Window class.
Dialog A top-level display surface (a window) with a border and title. An instance of the Dialog class cannot exist without an associated instance of the Frame class.
PanelA generic container for holding components. An instance of the Panel class provides a container to which to add components.
Step of AWT
• Import java.awt.*;• class ClassName extends Frame{
public ClassName(){}public static void main(String args[]){new ClassName();}}
Component of AWT
How to create Anatomy of form
import java.awt.*;
class TestAWT1 extends Frame { public TestAWT1(String s) { super(s); Panel P=new Panel(); setBackground(Color.yellow); setLayout(new FlowLayout()); Button pushButton = new Button("press me"); P.add(pushButton); add(P); } public static void main(String[] args) { TestAWT1 screen = new TestAWT1("Computer Bactouk Center"); screen.setSize(500,100); screen.setVisible(true); } }
EventControlName.addActionListener(
new ActionListener(){
public void actionPerform(ActionEvent e){
//do sth here}
});
Install window Builder in eclipse
Help=>Install New Software=>General Purpose Tools
Online downloading
window Builder in eclipseNew=>Other=>Window BuilderNote: Design
window Builder in eclipseHelp=>Install new Software=>add
Next=>Finish