chapter iii(building a simple user interface)

27
GUI(Building a Simple User Interface)

Upload: chhom-karath

Post on 15-Apr-2017

112 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Chapter iii(building a simple user interface)

GUI(Building a Simple User Interface)

Page 2: Chapter iii(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.

Page 3: Chapter iii(building a simple user interface)

AWT Controls, Layout Managers, and Menus

• Control Fundamentals– Labels– Push buttons– Check boxes– Choice lists– Lists– Scroll bars– Text editing

Page 4: Chapter iii(building a simple user interface)

Layout

• Layout Manager• Set Bound កូអរដោ�ដោ�

Page 5: Chapter iii(building a simple user interface)

Layout Manager• Flow Layout

• Grid Layout

• Border Layout

• Card Layout

Page 6: Chapter iii(building a simple user interface)

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

Page 7: Chapter iii(building a simple user interface)

Component tree

Page 8: Chapter iii(building a simple user interface)

Types of components

Page 9: Chapter iii(building a simple user interface)

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.

Page 10: Chapter iii(building a simple user interface)

Step of AWT

• Import java.awt.*;• class ClassName extends Frame{

public ClassName(){}public static void main(String args[]){new ClassName();}}

Page 11: Chapter iii(building a simple user interface)

Component of AWT

Page 12: Chapter iii(building a simple user interface)

How to create Anatomy of form

Page 13: Chapter iii(building a simple user interface)

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); } }

Page 14: Chapter iii(building a simple user interface)
Page 15: Chapter iii(building a simple user interface)
Page 16: Chapter iii(building a simple user interface)
Page 17: Chapter iii(building a simple user interface)
Page 18: Chapter iii(building a simple user interface)
Page 19: Chapter iii(building a simple user interface)

EventControlName.addActionListener(

new ActionListener(){

public void actionPerform(ActionEvent e){

//do sth here}

});

Page 20: Chapter iii(building a simple user interface)
Page 21: Chapter iii(building a simple user interface)
Page 22: Chapter iii(building a simple user interface)
Page 23: Chapter iii(building a simple user interface)

Install window Builder in eclipse

Help=>Install New Software=>General Purpose Tools

Online downloading

Page 24: Chapter iii(building a simple user interface)

window Builder in eclipseNew=>Other=>Window BuilderNote: Design

Page 25: Chapter iii(building a simple user interface)

window Builder in eclipseHelp=>Install new Software=>add

Next=>Finish

Page 26: Chapter iii(building a simple user interface)
Page 27: Chapter iii(building a simple user interface)