Swing Refresher - PowerPoint PPT Presentation

About This Presentation
Title:

Swing Refresher

Description:

Scroll Pane. Split Pane. Tabbed Pane. General-Purpose Containers ... Layered Pane. Root Pane. Special ... tabbedPane.addTab('Three', icon, panel3, 'Still ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 16
Provided by: annetteb6
Category:

less

Transcript and Presenter's Notes

Title: Swing Refresher


1
Swing Refresher
  • David Merrill
  • 5/14/2002
  • http//cs377a.stanford.edu/

2
What is Swing?
  • The Java Foundation Classes (JFC) API extends the
    original Abstract Window Toolkit (AWT) by adding
    a comprehensive set of graphical user interface
    class libraries.
  • JFC/Swing components include
  • Pluggable Look and Feel
  • Accessibility API
  • Java 2DTM API (Java 2 only)
  • Drag and Drop (Java 2 only)
  • AWT
  • Internationalization

3
JFC/Swing GUI Components
  • Written in the Java programming language
  • Customizable look-and-feel
  • No reliance on the native windowing system
  • Incorporated in the Java 2 platform

4
JFC/Swing GUI Components
Top-Level Containers
Applet
Dialog
Frame
5
JFC/Swing GUI Components
General-Purpose Containers
Tabbed Pane
Split Pane
Scroll Pane
Toolbar
Panel
6
JFC/Swing GUI Components
Special-Purpose Containers
Internal Frame
Layered Pane
Root Pane
7
JFC/Swing GUI Components
Basic Controls
List
Combobox
Buttons
Slider
Menu
Text Fields
8
JFC/Swing GUI Components
Uneditable Information Displays
Progress Bar
Label
Tooltip
9
JFC/Swing GUI Components
Editable Displays of Formatted Information
Tree
Text
Table
Color Chooser
File Chooser
10
JFrame
  • public static void main(String s)
  • JFrame frame new
    JFrame("FrameDemo")
  • frame.addWindowListener(new
    WindowAdapter()
  • public void
    windowClosing(WindowEvent e) System.exit(0)
  • )
  • //...create a blank label, set
    its preferred size...
  • frame.getContentPane().add(empty
    Label, BorderLayout.CENTER)
  • frame.pack()
  • frame.setVisible(true)

11
JTabbedPane
  • ImageIcon icon new
    ImageIcon("images/middle.gif")
  • JTabbedPane tabbedPane new
    JTabbedPane()
  • Component panel1
    makeTextPanel("Blah") //(returns a JPanel)
  • tabbedPane.addTab("One", icon,
    panel1, "Does nothing")
  • tabbedPane.setSelectedIndex(0)
  • Component panel2
    makeTextPanel("Blah blah")
  • tabbedPane.addTab("Two", icon,
    panel2, "Does twice as much nothing")
  • Component panel3
    makeTextPanel("Blah blah blah")
  • tabbedPane.addTab("Three", icon,
    panel3, "Still does nothing")
  • Component panel4
    makeTextPanel("Blah blah blah blah")
  • tabbedPane.addTab("Four", icon,
    panel4, "Does nothing at all")

12
JTabbedPane
  • ImageIcon icon new
    ImageIcon("images/middle.gif")
  • JTabbedPane tabbedPane new
    JTabbedPane()
  • Component panel1
    makeTextPanel("Blah") //(returns a JPanel)
  • tabbedPane.addTab("One", icon,
    panel1, "Does nothing")
  • tabbedPane.setSelectedIndex(0)
  • Component panel2
    makeTextPanel("Blah blah")
  • tabbedPane.addTab("Two", icon,
    panel2, "Does twice as much nothing")
  • Component panel3
    makeTextPanel("Blah blah blah")
  • tabbedPane.addTab("Three", icon,
    panel3, "Still does nothing")
  • Component panel4
    makeTextPanel("Blah blah blah blah")
  • tabbedPane.addTab("Four", icon,
    panel4, "Does nothing at all")

13
JGlassPane
  • private void redispatchMouseEvent(Mou
    seEvent e, boolean repaint)
  • // get the point from the MouseEvent
  • int eventID e.getID()
  • if (containerPoint.y lt 0)
  • inMenuBar true
  • //...set container and
    containerPoint accordingly...
  • testForDrag(eventID)
  • component SwingUtilities.getDe
    epestComponentAt(

  • container,

  • containerPoint.x,

  • containerPoint.y)
  • if (component.equals(liveButton)
    )
  • inButton true
  • testForDrag(eventID)
  • if (inMenuBar inButton
    inDrag)

14
JMenuBar
  • //in the constructor for a JFrame
    subclass
  • JMenuBar menuBar
  • JMenu menu, submenu
  • JMenuItem menuItem
  • JCheckBoxMenuItem cbMenuItem
  • JRadioButtonMenuItem rbMenuItem
  • ...
  • //Create the menu bar.
  • menuBar new JMenuBar()
  • setJMenuBar(menuBar)
  • //Build the first menu.
  • menu new JMenu("A Menu")
  • menu.setMnemonic(KeyEvent.VK_A)
  • menu.getAccessibleContext().setAcces
    sibleDescription("The only menu in this program
    that has menu items")
  • menuBar.add(menu)
  • //a group of JMenuItems
  • menuItem new JMenuItem("A
    text-only menu item",KeyEvent.VK_T)

15
URL

http//java.sun.com/docs/books/tutorial/uiswing/co
mponents/components.html
Write a Comment
User Comments (0)
About PowerShow.com