1 / 15

Swing Refresher

Swing Refresher. David Merrill 5/14/2002 http://cs377a.stanford.edu/. 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:

glen
Download Presentation

Swing Refresher

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Swing Refresher David Merrill 5/14/2002 http://cs377a.stanford.edu/ CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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 CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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 CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  4. JFC/Swing GUI Components Top-Level Containers Applet Dialog Frame CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  5. JFC/Swing GUI Components General-Purpose Containers Tabbed Pane Split Pane Scroll Pane Toolbar Panel CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  6. JFC/Swing GUI Components Special-Purpose Containers Internal Frame Layered Pane Root Pane CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  7. JFC/Swing GUI Components Basic Controls List Combobox Buttons Slider Menu Text Fields CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  8. JFC/Swing GUI Components Uneditable Information Displays Progress Bar Label Tooltip CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  9. JFC/Swing GUI Components Editable Displays of Formatted Information Tree Text Table Color Chooser File Chooser CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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(emptyLabel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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"); CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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"); CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  13. JGlassPane private void redispatchMouseEvent(MouseEvent e, boolean repaint) { // get the point from the MouseEvent int eventID = e.getID(); if (containerPoint.y < 0) { inMenuBar = true; //...set container and containerPoint accordingly... testForDrag(eventID); } component = SwingUtilities.getDeepestComponentAt( container, containerPoint.x, containerPoint.y); if (component.equals(liveButton)) { inButton = true; testForDrag(eventID); } if (inMenuBar || inButton || inDrag) { ...//Redispatch the event to component... } Etc… CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  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().setAccessibleDescription("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); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription(“This doesn't really do anything"); menu.add(menuItem); CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

  15. URL http://java.sun.com/docs/books/tutorial/uiswing/components/components.html CS377A: A Programming Approach to HCI • Jan Borchers • Spring 2002

More Related