Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS377A: A Programming Approach to HCI Jan Borchers Spring 20021 Swing Refresher David Merrill 5/14/2002

Similar presentations


Presentation on theme: "CS377A: A Programming Approach to HCI Jan Borchers Spring 20021 Swing Refresher David Merrill 5/14/2002"— Presentation transcript:

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

2 CS377A: A Programming Approach to HCI Jan Borchers Spring 20022 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 CS377A: A Programming Approach to HCI Jan Borchers Spring 20023 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 CS377A: A Programming Approach to HCI Jan Borchers Spring 20024 JFC/Swing GUI Components Applet DialogFrame Top-Level Containers

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

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

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

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

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

10 CS377A: A Programming Approach to HCI Jan Borchers Spring 200210 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); }

11 CS377A: A Programming Approach to HCI Jan Borchers Spring 200211 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 CS377A: A Programming Approach to HCI Jan Borchers Spring 200212 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 CS377A: A Programming Approach to HCI Jan Borchers Spring 200213 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…

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

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


Download ppt "CS377A: A Programming Approach to HCI Jan Borchers Spring 20021 Swing Refresher David Merrill 5/14/2002"

Similar presentations


Ads by Google