Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing a User Interface with Swing Assignment Swing: Update code of an earlier program.

Similar presentations


Presentation on theme: "Designing a User Interface with Swing Assignment Swing: Update code of an earlier program."— Presentation transcript:

1 Designing a User Interface with Swing Assignment Swing: Update code of an earlier program

2 Swing: Part of the Java Foundational Classes JDK1.2 §Expanded components §Better event handling §Selectable look & Feel §Extends AWT

3 Benefits of Swing §Swing provides for a different Look & Feel §Metal is the name of new interface in Java §All Components Compatibility (www…) §All Components written in Java(not so earlier) §import java.awt.swing.*; OR §javax.swing in Beta 4 (and up)

4 An Applications Framework §FRAMEWORK.JAVA l Just provides a frame (no components) §SWINGER.JAVA l A button “I receive a disproportionate amount of pleasure from being clicked. Please interact with me.” l Jframe NEW term “ an intermediate container called the content pane”

5 Jframe subdivided into panes §Create Jframe l Jframe frame = new Swinger( ); §Add all components (use add(Component)) l pane.add(hotbutton) §Make the Jpanel l Jpanel pane = new Jpanel( );

6 Working with Swing §NEW TERM icon l http://www.zeldman.com l (.gif files added to the icon ImageIcon una = new ImageIcon(“unabom.gif”); §http://www.prefect.com/java21

7 Swing §Labels Jlabel(String, int) §Buttons “ §TextFields JTextArea(int, int) §TextAreas “ §Check Boxes and Radio Buttons §Choice Lists“ §Scrollbars JScrollBar( int, int, int, int, int)

8 SwingColorTest §An “old” program revisited & Updated It is the “old” Hue Saturation & Brightness OR R G B §All done with Swing

9 New Swing UI manager §A Swing Layout manager/ user-interface manager l Windows 95 or NT Look & Feel Motif X- Window, Metal, Swing’s cross platform “ “ §try { UIManager.setLookAndFeel( §UIManager.getCrossPlatformLookAndFeel Classname( )); } catch(Exception e) { System.err.println(“Can’t set look and feel: + e;}

10 Keyboard Mnemonics §A key Accelerator l purpose (without a mouse) - use control keys in combination with other keys to function instead of mouse l Jbutton infoButton = new Jbutton(“Info”)’ l infoButton.setMnemonic(‘I’); l Pressing Alt+ I causes “InfoButton” click

11 It’s ToolTime with Tim Allen Kidding … ToolTips §JScrollBar seed = JScrollBar( ); §Speed.setToolTip ( “Move to set animation speed”); l limit ToolTip ONLY one line long

12 Component Descriptions & Names §1. Get AssessibleContext( ) method on the component §2. Call setAcccessibleDescription(String) method on that AccessibleContext object §The string argument should be the component’s text description

13 Standard Dialog Boxes §Like Visual BASIC “Windows” that ask a small/simple question, warn, or provide message §ConfirmDialog = Y/N Cancel §InputDialog = prompt input §MessageDialog = message §OptionDialog = All of the above

14 Example §Int response; §response = JOptionPane.showConfirmDialog(null, “Should I delete all your irreplaceable personal files”); §MORE figures/code demo. Use of Dialog Boxes

15 INFO.JAVA §Last example of complete program in chapter. Uses Dialog boxes - Swing


Download ppt "Designing a User Interface with Swing Assignment Swing: Update code of an earlier program."

Similar presentations


Ads by Google