Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Designing a User Interface with Swing Assignment Swing: Update code of an earlier program Swing: Part of the Java Foundational Classes JDK1.2 Expanded components Better event handling Selectable look & Feel Extends AWT 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) An Applications Framework FRAMEWORK.JAVA Just provides a frame (no components) SWINGER.JAVA A button “I receive a disproportionate amount of pleasure from being clicked. Please interact with me.” Jframe NEW term “ an intermediate container called the content pane” Jframe subdivided into panes Create Jframe Jframe frame = new Swinger( ); Add all components (use add(Component)) pane.add(hotbutton) Make the Jpanel Jpanel pane = new Jpanel( ); Working with Swing NEW TERM icon http://www.zeldman.com (.gif files added to the icon • ImageIcon una = new ImageIcon(“unabom.gif”); http://www.prefect.com/java21 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) SwingColorTest An “old” program revisited & Updated • It is the “old” Hue Saturation & Brightness OR • RGB All done with Swing New Swing UI manager A Swing Layout manager/ user-interface manager Windows 95 or NT Look & Feel Motif XWindow, Metal, Swing’s cross platform “ “ try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeel Classname( )); } catch(Exception e) { System.err.println(“Can’t set look and feel: + e;} Keyboard Mnemonics A key Accelerator purpose (without a mouse) - use control keys in combination with other keys to function instead of mouse Jbutton infoButton = new Jbutton(“Info”)’ infoButton.setMnemonic(‘I’); Pressing Alt+ I causes “InfoButton” click It’s ToolTime with Tim Allen Kidding … ToolTips JScrollBar seed = JScrollBar( ); Speed.setToolTip ( “Move to set animation speed”); limit ToolTip ONLY one line long 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 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 Example Int response; response = JOptionPane.showConfirmDialog(null, “Should I delete all your irreplaceable personal files”); MORE figures/code demo. Use of Dialog Boxes INFO.JAVA Last example of complete program in chapter. Uses Dialog boxes - Swing