Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Spring 2002 © University of Stirling IT82: Multimedia 1 Java/JDK/SDK/… !!! Java language Development Tools Java 1.0 JDK 1.0.* Java 1.1 JDK 1.1.* Java 2 Spring 2002 © University of Stirling SDK 1.2/1.3/1.4 IT82: Multimedia 2 1 JFC and Swing Java Foundation Classes (JFC) Swing: • Swing components • Pluggable Look and Feel • Accessibility API only available • Java2D API in Java 2 • Drag and Drop API Spring 2002 © University of Stirling IT82: Multimedia 3 JFC Swing • interface components written in Java • non-window-system-specific • customizable Pluggable Look-and-Feel • switch the look of a suite of applications without having to re-jig the components of each one • a number of standard looks and feels provided Spring 2002 © University of Stirling IT82: Multimedia 4 2 JFC Accessibility API • allows assistive technologies to be used with Java components – e.g. screen readers, screen magnifiers, speech recognition Java2D API • more advanced graphics drawing facilities – e.g. more sophisticated geometry, transformations, painting styles, image processing Drag-and-Drop API • allows dragging and dropping between Java and nonJava applications Spring 2002 © University of Stirling IT82: Multimedia 5 Swing and AWT • Swing has versions of all the components supplied by the Abstract Windowing Toolkit (AWT) • … plus lots more! • Swing components typically extend (are subclasses of) AWT components, e.g. Spring 2002 © University of Stirling IT82: Multimedia 6 3 AWT • One big difference is in the hierarchies of containers: • … and you can do (eg) Spring 2002 © University of Stirling f.add(child) IT82: Multimedia 7 Swing f.getContentPane().add(child); Spring 2002 © University of Stirling IT82: Multimedia 8 4 Visualizing the Panes Spring 2002 © University of Stirling IT82: Multimedia 9 Swing Components Containers • Top-Level • General-Purpose • Special-Purpose Atomic Components • Basic Controls • Information Displays – Uneditable – Editable Spring 2002 © University of Stirling IT82: Multimedia 10 5 Top-level Containers At the top of any containment hierarchy, you will find one of these: Applet Dialogue Frame JApplet JDialog JOptionPane JFrame Spring 2002 © University of Stirling IT82: Multimedia 11 General-purpose Containers (Intermediate containers of many uses) Toolbar Panel JToolBar Jpanel Split Pane Scroll Pane Tabbed Pane JSplitPane JScrollPane JTabbedPane Spring 2002 © University of Stirling IT82: Multimedia 12 6 Special-purpose Containers (Intermediate containers with specific roles) Internal Frame Layered Pane JInternalFrame JLayeredPane Root Pane JRootPane Spring 2002 © University of Stirling Buttons IT82: Multimedia Controls 13 Combo Box List Jbutton Menu JList Slider JComboBox Text field JMenu JMenuItem JSlider JTextField Spring 2002 © University of Stirling IT82: Multimedia 14 7 Information Displays (uneditable, solely to give information) Label Progress Bar JLabel JProgressBar Spring 2002 © University of Stirling File Chooser ToolTip JToolTip IT82: Multimedia Information Displays 15 Colour Chooser (editable, formatted) JFileChooser Table Text JColorChooser Tree JTable JTextArea JTree Spring 2002 © University of Stirling IT82: Multimedia 16 8 Layout Managers (standard ones) Managers available: • Flow • Card • Border • Box • Grid • GridBag (complicated!) • customized Spring 2002 © University of Stirling IT82: Multimedia BoxLayout 17 BorderLayout GridBagLayout GridLayout Spring 2002 © University of Stirling IT82: Multimedia 18 9 ActionListener A Whole Lot of Listeners ComponentListener DocumentListener ContainerListener CaretListener AncestorListener FocusListener Spring 2002 © University of Stirling CellEditorListener ChangeListener HyperlinkListener InternalFrameListener MenuListener MouseListener ItemListener KeyListener MouseInputListener ListSelectionListener TreeModelListener ListDataListener MenuKeyListener MenuDragMouseListener MouseMotionListener TableColumnModelListener PopupMenuListener TableModelListener TreeExpansionListener TreeSelectionListener UndoableEditListener TreeWillExpandListener WindowListener IT82: Multimedia 19 Example SwingApplication Spring 2002 © University of Stirling IT82: Multimedia 20 10 Practical Swing Conversion Tips • Don’t forget the import javax.swing.*; • Remember about separate content panes for JFrame • Don’t call the paint method directly - use paintComponent • Stick to either AWT or Swing - in particular, – Don’t mix heavy and light components Spring 2002 © University of Stirling IT82: Multimedia 21 Heavy and Light • “Heavy”components have their own screen resources, “light”components borrow them – AWT components are heavy – Swing components are light • Mixing them causes problems, because of: – lightweights can be transparent, heavies are opaque – heavies always appear rectangular – mouse events on a lightweight component fall through to the parent of the component - not so with heavies – heavy components are always on top Spring 2002 © University of Stirling IT82: Multimedia 22 11 Heavy and Light Spring 2002 © University of Stirling IT82: Multimedia 23 Why use Swing? (in case you weren’t already converted) • Big range of snazzy (usable too!) features: – e.g. icons on buttons, toolbars, tabbed panes, sliders, file choosers,… .. • Pluggable Look and Feel gives a range of choice for interface styles non-window-system-dependent • Built-in accessibility support Spring 2002 © University of Stirling IT82: Multimedia 24 12 More Swing (Information for if you want to go further into Swing) Many Java books cover some Swing • One book is by Mary Campione and Kathy Walrath: “The JFC Swing tutorial” • This book is the portable version • of the online Swing tutorial, at http://java.sun.com/docs/books/tutorial/uiswing/ • More information than you could ever possibly want at the sun site, java.sun.com Spring 2002 © University of Stirling IT82: Multimedia 25 Plug-in Look and Feel Samples Java MacOS Windows Spring 2002 © University of Stirling Motif IT82: Multimedia 26 13 Java Look and Feel Guidelines • Very comprehensive, a valuable resource • Book form, as well as online at java.sun.com/products/jlf/ • Covers structural design, as well as visual/layout guidelines • Detailed guidelines on various topics, including – Interface components – Mouse behaviour – Using graphics Spring 2002 © University of Stirling IT82: Multimedia 27 Look and Feel Graphics Spring 2002 © University of Stirling IT82: Multimedia 28 14 Extract from Graphics Guidelines Spring 2002 © University of Stirling IT82: Multimedia 29 End of Lecture Spring 2002 © University of Stirling IT82: Multimedia 30 15