Gui Interfaces a la Swing - PowerPoint PPT Presentation

About This Presentation
Title:

Gui Interfaces a la Swing

Description:

if it ain't got that swing. Duke Ellington. Simple Gui layout Design. Four main decisions ... what to gather from user, what to show him. 2. Particular objects ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 9
Provided by: dennis72
Learn more at: https://www.ics.uci.edu
Category:

less

Transcript and Presenter's Notes

Title: Gui Interfaces a la Swing


1
Gui Interfacesa la Swing
  • Up to speed with Swing by
  • Steven Gutz is a good source
  • It dont mean a thing
  • if it aint got that swing
  • Duke Ellington

2
Simple Gui layout Design
  • Four main decisions
  • 1. User Interactions
  • what to gather from user, what to show
    him
  • 2. Particular objects on screen
  • JTextField, TextArea, JButton, JPanels,
    JLabels, JFrame...
  • 3. General layout of Screen
  • borderlayout, gridlayout, flowlayout,.
  • 4. Listeners
  • connect user actions with program
    activities
  • WindowListeners, ActionListeners,
    ItemListeners, .

3
Minimal Objects and methods
  • JFrame where you start
  • Container mainPane getContentPane() is where
    you add other components.
  • JPanels
  • container for other objects including Jpanels
  • setLayoutManager(..)
  • JTextField(int size) setText, getText,
    addActionListener
  • TextArea(int row, int col) append
  • JButton(String s) named button,
    addActionListener
  • JLabel(String s) just a string
  • More JTabbedPane, ScollBars, Lists, Checkboxes,
    Menus, Dialogs, PopUps, Sliders,Toolbars..and on
    and on

4
Layout Managers
  • FlowLayout()
  • right to left with wrap around
  • default manager for JPanel
  • BorderLayout()
  • north, south, east, west, center
  • default for contentPane
  • GridLayout(int row, int columns)
  • row and columns
  • GridBag Layout (..)
  • hurts my head
  • Layout Managers can be nested.

5
Listeners are Interfaces
  • WindowListeners
  • respond to window events, such as miniminizing
    window, closing, moving, maximizing, etc.
  • Window will not Close! Need to add a listener.
  • Has 7 methods, I.e. obligations.
  • ActionListeners
  • For JButtons, responds to clicking on buttons
  • For JTextFields, responds to enter
  • Still need to define the activity
  • Only 1 method actionPerformed(ActionEvent ae)
  • ItemListeners, MouseListeners, KeyListeners,.
  • 11 listeners at last count.

6
Events
  • ActionEvent
  • button pressed, text entered, .
  • WindowEvent
  • windowIconified, windowClosed, windowOpened,
  • Key Events
  • keyTyped, keyPressed, keyReleased
  • MouseEvents
  • mouseClicked, mousePressed, mouseReleased,
    mouseDragged, mouseMoved,...
  • TextEvent
  • textValue changed,..
  • And on and on

7
Closeable Hello World
  • import javax.swing. // for J stuff
  • import java.awt.event. // for listeners
  • import java.awt. // for the layout managers
  • class Driver extends JFrame
  • public static void main(String args)
  • Driver driver new Driver()
  • driver.show() // without this, you get
    nothing
  • Driver()
  • addWindowListener(new WindowDestroyer())
    //needed to close window
  • Container mainPane getContentPane()
    // default border layout
  • mainPane.add(new Jlabel(Hello World))

8
Window Destroyer
  • import java.awt.event.
  • class WindowDestroyer extends WindowAdapter
  • public void windowClosing(WindowEvent we)
  • System.exit(0)
  • WindowListener has 7 methods to define.
  • WindowAdapter defines them all to do nothing.
Write a Comment
User Comments (0)
About PowerShow.com