GUI - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

GUI

Description:

... size set before they will show up on the screen. setSize(500,100) ... Choice: pop-up list. Label: string, left aligned. List: select from several alternatives ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 18
Provided by: robertb61
Category:
Tags: gui | popup | southwest

less

Transcript and Presenter's Notes

Title: GUI


1
GUI
  • component buttons, menus, etc.
  • event handling system
  • containers to add controls to
  • layout manager
  • graphics operations
  • controls press, scroll, choose between

2
procedure
  • declare controls
  • add controls to a container
  • add an event handler

3
component
  • javap java.awt.Component
  • location
  • size
  • color
  • etc.
  • java foundation classes - more controls

4
container
  • holds scrollbar, textfields, butons, etc
  • must have their size set before they will show up
    on the screen
  • setSize(500,100)

5
container
  • Window basic free floating window that can be
    moved
  • Panel nested in some larger container
  • Frame subclass of Window with title and menubar

6
public class myFrame( static Frame fnew
Frame(myFrame) public static void main(
String a) f.setSize(300,100) f.show()

7
Layout in a Container
  • setLayout( new FlowLayout() )
  • FlowLayout components added left to right,
    keeping them centered, starting a new line when
    necessary
  • you may specify LEFT or RIGHT justified instead
    of centered
  • default for applet

8
Border Layout
  • five components may be added
  • they are positioned at north, east, south, west
    and center
  • default for Frame

9
Grid Layout
  • setLayout( new GridLayout(2,3))
  • this makes two rows of three components
  • all components are the same size
  • GridBagLayout is a much more complicated version
    of GridLayout

10
mixing layouts
  • create different containers
  • set different layout managers in the different
    containers
  • put the different containers into another
    container where you want them

11
controls
  • Checkbox on or off control
  • CheckboxGroup group of checkboxs
  • Choice pop-up list
  • Label string, left aligned
  • List select from several alternatives
  • TextField can enter a single line of chars
  • TextArea several lines long

12
Checkbox
Checkbox cbnew Checkbox(small) add(cb) public
void init() cb.addItemListener(new
ItemListener() public void itemStateChanged(Ite
mEvent ie) System.out.println(ie.paramString())
)
13
Menu
  • Frame f new Frame(Editor)
  • MenuBar mbnew MenuBar()
  • Menu file new Menu(file, true)
  • //true is for tearoff menu

14
public void init() file.add(new
MenuItem(new)) file.add(new
MenuItem(open)) file.add(new
MenuItem(save)) file.add(new
MenuItem(-)) file.add(new MenuItem(exit))
mb.add(file) f.setSize(500,100) f.setMenuBar(
mb) f.show()
15
file.addActionListener( new ActionListener() pu
blic void actionPerformed(ActionEvent
e) System.out.println(field is
e.getActionCommand() ) )
16
convert applet to application
  • make the top level class extend Frame, not Applet
  • set the layout manager to FlowLayout
  • add a main routine
  • if the applet read parameters, have the main read
    command line arguments
  • main should instantiate an object of the class

17
applet to application
  • the constructor should call start() and init()
  • add a menu with an Exit item or an exit button
Write a Comment
User Comments (0)
About PowerShow.com