Free web hosting music - Chapter 13 Graphical User Interface Components: Part 2
Tuesday, May 8th, 2007Chapter 13 Graphical User Interface Components: Part 2 797 JSliders generate ChangeEvents (package javax.swing.event) when the user interacts with a JSlider. A ChangeListener (package javax.swing.event) defines method stateChanged that can respond to ChangeEvents. Method getValue of class JSlider returns the current thumb position. A JFrame is a window with a title bar and a border. Class JFrame is a subclass of java.awt.Frame (which is a subclass of java.awt.Window). Class JFrame supports three operations when the user closes the window. By default, a JFrame is hidden when the user closes a window. This can be controlled with JFrame method setDefaultCloseOperation. Interface WindowConstants (package javax.swing) defines three constants for use with this method DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE and HIDE_ON_CLOSE (the default). By default, a window is not displayed on the screen until its setVisible method is called with true as an argument. A window can also be displayed by calling its show method. A window s size should be set with a call to method setSize. The position of a window when it appears on the screen is specified with method setLocation. All windows generate window events when the user manipulates the window. Event listeners are registered for window events with method addWindowListener of class Window. The WindowListener interface provides seven methods for handling window events windowActivated (called when the window is made active by clicking the window), windowClosed (called after the window is closed), windowClosing (called when the user initiates closing of the window), windowDeactivated (called when another window is made active), window- Iconified(called when the user minimizes a window), windowDeiconified (called when a window is restored from being minimized) and windowOpened(called when a window is first displayed on the screen). The command-line arguments are automatically passed to main as the array of Strings called args. The first argument after the application class name is the first String in the array args, and the length of the array is the total number of command-line arguments. Menus are an integral part of GUIs. Menus allow the user to perform actions without unnecessarily cluttering a graphical user interface with extra GUI components. In Swing GUIs, menus can be attached only to objects of the classes that provide method set- JMenuBar. Two such classes are JFrameand JApplet. The classes used to define menus are JMenuBar, JMenuItem, JMenu, JCheckBoxMenu- Item and class JRadioButtonMenuItem. A JMenuBaris a container for menus. A JMenuItem is a GUI component inside a menu that, when selected, causes an action to be performed. A JMenuItem can be used to initiate an action or it can be a submenu that provides more menu items from which the user can select. A JMenu contains menu items and can be added to a JMenuBar or to other JMenus as submenus. When a menu is clicked, the menu expands to show its list of menu items. When a JCheckBoxMenuItem is selected, a check appears to the left of the menu item. When the JCheckBoxMenuItemis selected again, the check to the left of the menu item is removed. When multiple JRadioButtonMenuItems are maintained as part of a ButtonGroup, only one item in the group can be selected at a given time. When a JRadioButtonMenuItem is selected, a filled circle appears to the left of the menu item. When another JRadioButtonMenu- Item is selected, the filled circle to the left of the previously selected menu item is removed. JFrame method setJMenuBar attaches a menu bar to a JFrame.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services