Archive for July, 2007

768 Graphical User Interface Components: Part 2 Chapter (Web site traffic)

Sunday, July 22nd, 2007

768 Graphical User Interface Components: Part 2 Chapter 13 33 34 // create strut and add buttons to boxes[ 1 ] 35 for ( int count = 0; count < SIZE; count++ ) { 36 boxes[ 1 ].add( Box.createVerticalStrut( 25 ) ); 37 boxes[ 1 ].add( new JButton( "boxes[1]: " + count ) ); 38 } 39 40 // create horizontal glue and add buttons to boxes[ 2 ] 41 for ( int count = 0; count < SIZE; count++ ) { 42 boxes[ 2 ].add( Box.createHorizontalGlue() ); 43 boxes[ 2 ].add( new JButton( "boxes[2]: " + count ) ); 44 } 45 46 // create rigid area and add buttons to boxes[ 3 ] 47 for ( int count = 0; count < SIZE; count++ ) { 48 boxes[ 3 ].add( 49 Box.createRigidArea( new Dimension( 12, 8 ) ) ); 50 boxes[ 3 ].add( new JButton( "boxes[3]: " + count ) ); 51 } 52 53 // create vertical glue and add buttons to panel 54 JPanel panel = new JPanel(); 55 panel.setLayout( 56 new BoxLayout( panel, BoxLayout.Y_AXIS ) ); 57 58 for ( int count = 0; count < SIZE; count++ ) { 59 panel.add( Box.createGlue() ); 60 panel.add( new JButton( "panel: " + count ) ); 61 } 62 63 // place panels on frame 64 container.add( boxes[ 0 ], BorderLayout.NORTH ); 65 container.add( boxes[ 1 ], BorderLayout.EAST ); 66 container.add( boxes[ 2 ], BorderLayout.SOUTH ); 67 container.add( boxes[ 3 ], BorderLayout.WEST ); 68 container.add( panel, BorderLayout.CENTER ); 69 70 setSize( 350, 300 ); 71 setVisible( true ); 72 73 } // end constructor 74 75 // execute application 76 public static void main( String args[] ) 77 { 78 BoxLayoutDemo application = new BoxLayoutDemo(); 79 80 application.setDefaultCloseOperation( 81 JFrame.EXIT_ON_CLOSE ); 82 } 83 84 } // end class BoxLayoutDemo Fig. 13.15 Demonstrating the BoxLayoutlayout manager (part 2 of 3).
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Chapter 13 (Web site) Graphical User Interface Components: Part 2

Sunday, July 22nd, 2007

Chapter 13 Graphical User Interface Components: Part 2 767 13.13 BoxLayoutLayout Manager The BoxLayoutlayout manager arranges GUI components horizontally along the x-axis or vertically along the y-axis of a container. The program of Fig. 13.15 demonstrates Box- Layoutand the container class Boxthat uses BoxLayoutas its default layout manager. In the constructor for class BoxLayoutDemo, lines 19 20 obtain a reference to the content pane and set its layout to a BorderLayout with 30 pixels of horizontal and 30 pixels of vertical gap space between components. The space is to help isolate each of the containers with BoxLayoutin this example. Lines 23 28 define an array of Box container references called boxes and initialize each element of the array with Box objects. Elements 0 and 2 of the array are initialized with staticmethod createHorizontalBoxof class Box, which returns a Boxcontainer with a horizontal BoxLayout (GUI components are arranged left-to-right). Elements 1 and 3 of the array are initialized with static method createVerticalBox of class Box, which returns a Boxcontainer with a vertical BoxLayout(GUI components are arranged top-to-bottom). 1 // Fig. 13.15: BoxLayoutDemo.java 2 // Demonstrating BoxLayout. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class BoxLayoutDemo extends JFrame { 12 13 // set up GUI 14 public BoxLayoutDemo() 15 { 16 super( “Demostrating BoxLayout” ); 17 final int SIZE = 3; 18 19 Container container = getContentPane(); 20 container.setLayout( new BorderLayout( 30, 30 ) ); 21 22 // create Box containers with BoxLayout 23 Box boxes[] = new Box[ 4 ]; 24 25 boxes[ 0 ] = Box.createHorizontalBox(); 26 boxes[ 1 ] = Box.createVerticalBox(); 27 boxes[ 2 ] = Box.createHorizontalBox(); 28 boxes[ 3 ] = Box.createVerticalBox(); 29 30 // add buttons to boxes[ 0 ] 31 for ( int count = 0; count < SIZE; count++ ) 32 boxes[ 0 ].add( new JButton( "boxes[0]: " + count ) ); Fig. 13.15 Demonstrating the BoxLayoutlayout manager (part 1 of 3).
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Photography web hosting - 766 Graphical User Interface Components: Part 2 Chapter

Sunday, July 22nd, 2007

766 Graphical User Interface Components: Part 2 Chapter 13 Line 30 creates JDesktopPane (package javax.swing) reference the- Desktop and assigns it a new JDesktopPane object. The JDesktopPane object manages the JInternalFramechild windows displayed in the JDesktopPane. Line 31 adds the JDesktopPaneto the application window s content pane. Lines 34 61 register an instance of an anonymous inner class that implements ActionListenerto handle the event when the user selects the newFramemenu item. When the event occurs, method actionPerformed (lines 40 57) creates a JInternalFrame object with lines 43 44. The JInternalFrame constructor used here requires five arguments a String for the title bar of the internal window, a boolean indicating whether the internal frame should be resizable by the user, a boolean indicating whether the internal frame should be closable by the user, a boolean indicating whether the internal frame should be maximizable by the user and a booleanindicating whether the internal frame should be minimizable by the user. For each of the boolean arguments, a truevalue indicates that the operation should be allowed. As with JFrames and JApplets, a JInternalFramehas a content pane to which GUI components can be attached. Line 47 gets a reference to the JInternalFrame s content pane. Line 48 creates an instance of our class MyJPanel(defined at lines 80 106) that is added to the JInternalFrame s content pane at line 49. Line 52 uses JInternalFrame method packto set the size of the child window. Method packuses the preferred sizes of the components on the content pane to determine the window s size. Class MyJPanel defines method getPreferredSize to specify the panel s preferred size. Line 55 adds the JInternalFrameto the JDesktopPane, and line 56 displays the JInternalFrame. Classes JInternalFrame and JDesktopPane provide many methods for managing child windows. See the on-line API documentation for a complete list of these methods. 13.12 Layout Managers In the preceding chapter, we introduced three layout managers FlowLayout, Border- Layoutand GridLayout. This section presents three additional layout managers (summarized in Figure 13.14). We discuss these layout managers in the sections that follow. Layout Manager Description BoxLayout A layout manager that allows GUI components to be arranged left-to-right or top-to-bottom in a container. Class Boxdefines a container with Box- Layoutas its default layout manager and provides static methods to create a Boxwith a horizontal or vertical BoxLayout. CardLayout A layout manager that stacks components like a deck of cards. If a component in the deck is a container, it can use any layout manager. Only the component at the top of the deck is visible. GridBagLayout A layout manager similar to GridLayout. Unlike GridLayout, each component size can vary and components can be added in any order. Fig. 13.14 Additional layout managers.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Chapter 13 Graphical User Interface Components: Part 2 (Free web design)

Saturday, July 21st, 2007

Chapter 13 Graphical User Interface Components: Part 2 765 Internal Frames Minimize Maximize Close Minimized internal frame Position the mouse over any corner of a child window to resize the window (if resizing is allowed). Maximized internal frame Fig. 13.13 Fig. 13.13 Creating a multiple document interface (part 3 of 3).
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

764 Graphical User Interface Components: Part (1 on 1 web hosting) 2 Chapter

Saturday, July 21st, 2007

764 Graphical User Interface Components: Part 2 Chapter 13 54 // attach internal frame to desktop and show it 55 theDesktop.add( frame ); 56 frame.setVisible( true ); 57 } 58 59 } // end anonymous inner class 60 61 ); // end call to addActionListener 62 63 setSize( 600, 440 ); 64 setVisible( true ); 65 66 } // end constructor 67 68 // execute application 69 public static void main( String args[] ) 70 { 71 DesktopTest application = new DesktopTest(); 72 73 application.setDefaultCloseOperation( 74 JFrame.EXIT_ON_CLOSE ); 75 } 76 77 } // end class DesktopTest 78 79 // class to display an ImageIcon on a panel 80 class MyJPanel extends JPanel { 81 private ImageIcon imageIcon; 82 83 // load image 84 public MyJPanel() 85 { 86 imageIcon = new ImageIcon( “jhtp4.png” ); 87 } 88 89 // display imageIcon on panel 90 public void paintComponent( Graphics g ) 91 { 92 // call superclass paintComponent method 93 super.paintComponent( g ); 94 95 // display icon 96 imageIcon.paintIcon( this, g, 0, 0 ); 97 } 98 99 // return image dimensions 100 public Dimension getPreferredSize() 101 { 102 return new Dimension( imageIcon.getIconWidth(), 103 imageIcon.getIconHeight() ); 104 } 105 106 } // end class MyJPanel Fig. 13.13 Fig. 13.13 Creating a multiple document interface (part 2 of 3).
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Chapter 13 (Web site developers) Graphical User Interface Components: Part 2

Saturday, July 21st, 2007

Chapter 13 Graphical User Interface Components: Part 2 763 // Fig. 13.13: DesktopTest.java // Demonstrating JDesktopPane. // Java core packages import java.awt.*; import java.awt.event.*; // Java extension packages import javax.swing.*; public class DesktopTest extends JFrame { private JDesktopPane theDesktop; // set up GUI public DesktopTest() { super( “Using a JDesktopPane” ); // create menu bar, menu and menu item JMenuBar bar = new JMenuBar(); JMenu addMenu = new JMenu( “Add” ); JMenuItem newFrame = new JMenuItem( “Internal Frame” ); addMenu.add( newFrame ); bar.add( addMenu ); setJMenuBar( bar ); // set up desktop theDesktop = new JDesktopPane(); getContentPane().add( theDesktop ); // set up listener for newFrame menu item newFrame.addActionListener( // anonymous inner class to handle menu item event new ActionListener() { // display new internal window public void actionPerformed( ActionEvent event ) { // create internal frame JInternalFrame frame = new JInternalFrame( “Internal Frame”, true, true, true, true ); // attach panel to internal frame content pane Container container = frame.getContentPane(); MyJPanel panel = new MyJPanel(); container.add( panel, BorderLayout.CENTER ); // set size internal frame to size of its contents frame.pack(); Fig. 13.13 Fig. 13.13 Creating a multiple document interface (part 1 of 3).
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

762 Graphical User Interface Components: Part 2 Chapter (Web design programs)

Saturday, July 21st, 2007

762 Graphical User Interface Components: Part 2 Chapter 13 Class UIManager (package javax.swing) contains publicstatic inner class LookAndFeelInfo that is used to maintain information about a look-and-feel. Line 14 declares an array of type UIManager.LookAndFeelInfo (notice the syntax used to access the inner class LookAndFeelInfo). Line 71 uses static method getInstalledLookAndFeels of class UIManager to get the array of UIManager.LookAndFeelInfo objects that describe the installed look-and-feels. Performance Tip 13.1 Each look-and-feel is represented by a Java class. UIManager method getInstalled- LookAndFeels does not load each class. Rather, it provides access to the names of each look-and-feel, so a choice of look-and-feel can be made (presumably one time at program startup). This reduces the overhead of loading additional classes that the program will not use. Utility method changeTheLookAndFeel (lines 80 93) is called by the event handler (defined in private inner class ItemHandler at lines 105 121) for the JRadioButtons at the bottom of the user interface. The event handler passes an integer representing the element in array looks that should be used to change the look-and-feel. Lines 84 85 use static method setLookAndFeel of class UIManager to change the look-and-feel. Method getClassName of class UIManager.LookAnd- FeelInfo determines the name of the look-and-feel class that corresponds to the UIManager.LookAndFeelInfo. If the look-and-feel class is not already loaded, it will be loaded as part of the call to setLookAndFeel. Line 86 uses static method updateComponentTreeUI of class SwingUtilities (package javax.swing) to change the look-and-feel of every component attached to its argument (this instance of class LookAndFeelDemo) to the new look-and-feel. The preceding two statements appear in a special block of code called a try block. This code is part of the exception-handling mechanism discussed in detail in the next chapter. This code is required in case lines 84 85 attempt to change the look-and-feel to a look-and-feel that does not exist. Lines 90 92 complete the exception-handling mechanism with a catchhandler that simply processes this problem (if it occurs) by printing an error message at the command line. 13.11 Using JDesktopPaneand JInternalFrame Many of today s applications use a multiple document interface (MDI) [i.e., a main window (often called the parent window) containing other windows (often called child windows)] to manage several open documents that are being processed in parallel. For example, many e-mail programs allow you to have several e-mail windows open at the same time so you can compose and/or read multiple e-mail messages. Similarly, many word processors allow the user to open multiple documents in separate windows so the user can switch between the documents without having to close the current document to open another document. The program of Fig. 13.13 demonstrates Swing s JDesktopPane and JInternal- Frame classes, which provide support for creating multiple document interfaces. The child windows simply display an image of the cover of this book. Lines 20 27 define a JMenuBar, a JMenu and a JMenuItem, add the JMenuItem to the JMenu, add the JMenu to the JMenuBarand set the JMenuBar for the application window. When the user selects the JMenuItemnewFrame, the program creates and displays a new JInternalFrame.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Chapter 13 Graphical User Interface Components: Part 2 (Top web site)

Friday, July 20th, 2007

Chapter 13 Graphical User Interface Components: Part 2 761 95 // execute application 96 public static void main( String args[] ) 97 { 98 LookAndFeelDemo application = new LookAndFeelDemo(); 99 100 application.setDefaultCloseOperation( 101 JFrame.EXIT_ON_CLOSE ); 102 } 103 104 // private inner class to handle radio button events 105 private class ItemHandler implements ItemListener { 106 107 // process user’s look-and-feel selection 108 public void itemStateChanged( ItemEvent event ) 109 { 110 for ( int count = 0; count < radio.length; count++ ) 111 112 if ( radio[ count ].isSelected() ) { 113 label.setText( "This is a " + 114 strings[ count ] + " look-and-feel" ); 115 comboBox.setSelectedIndex( count ); 116 117 changeTheLookAndFeel( count ); 118 } 119 } 120 121 } // end private inner class ItemHandler 122 123 } // end class LookAndFeelDemo Fig. 13.12 Fig. 13.12 Changing the look-and-feel of a Swing-based GUI (part 3 of 3). All the GUI components and event handling in this example have been covered before, so we concentrate on the mechanism for changing the look-and-feel in this example.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Yahoo web space - 760 Graphical User Interface Components: Part 2 Chapter

Friday, July 20th, 2007

760 Graphical User Interface Components: Part 2 Chapter 13 44 45 // attach NORTH panel to content pane 46 container.add( northPanel, BorderLayout.NORTH ); 47 48 // create array for radio buttons 49 radio = new JRadioButton[ strings.length ]; 50 51 // set up panel for SOUTH of BorderLayout 52 JPanel southPanel = new JPanel(); 53 southPanel.setLayout( 54 new GridLayout( 1, radio.length ) ); 55 56 // set up radio buttons for SOUTH panel 57 group = new ButtonGroup(); 58 ItemHandler handler = new ItemHandler(); 59 60 for ( int count = 0; count < radio.length; count++ ) { 61 radio[ count ] = new JRadioButton( strings[ count ] ); 62 radio[ count ].addItemListener( handler ); 63 group.add( radio[ count ] ); 64 southPanel.add( radio[ count ] ); 65 } 66 67 // attach SOUTH panel to content pane 68 container.add( southPanel, BorderLayout.SOUTH ); 69 70 // get installed look-and-feel information 71 looks = UIManager.getInstalledLookAndFeels(); 72 73 setSize( 300, 200 ); 74 setVisible( true ); 75 76 radio[ 0 ].setSelected( true ); 77 } 78 79 // use UIManager to change look-and-feel of GUI 80 private void changeTheLookAndFeel( int value ) 81 { 82 // change look and feel 83 try { 84 UIManager.setLookAndFeel( 85 looks[ value ].getClassName() ); 86 SwingUtilities.updateComponentTreeUI( this ); 87 } 88 89 // process problems changing look and feel 90 catch ( Exception exception ) { 91 exception.printStackTrace(); 92 } 93 } 94 Fig. 13.12 Fig. 13.12 Changing the look-and-feel of a Swing-based GUI (part 2 of 3).
We recommend high quality webhost to host and run your jsp application: christian web host services.

Chapter 13 Graphical (Web hosts) User Interface Components: Part 2

Friday, July 20th, 2007

Chapter 13 Graphical User Interface Components: Part 2 759 the look-and-feel to appear as a Microsoft Windows-style look-and-feel or a Motif-style (UNIX) look-and-feel. The program of Fig. 13.12 demonstrates how to change the look-and-feel of a Swing GUI. The program creates several GUI components so you can see the change in the look- and-feel of several GUI components at the same time. The first output window shows the standard metal look-and-feel, the second output window shows the Motif look-and-feel, and the third output window shows the Windows look-and-feel. 1 // Fig. 13.12: LookAndFeelDemo.java 2 // Changing the look and feel. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class LookAndFeelDemo extends JFrame { 12 13 private String strings[] = { “Metal”, “Motif”, “Windows” }; 14 private UIManager.LookAndFeelInfo looks[]; 15 private JRadioButton radio[]; 16 private ButtonGroup group; 17 private JButton button; 18 private JLabel label; 19 private JComboBox comboBox; 20 21 // set up GUI 22 public LookAndFeelDemo() 23 { 24 super( “Look and Feel Demo” ); 25 26 Container container = getContentPane(); 27 28 // set up panel for NORTH of BorderLayout 29 JPanel northPanel = new JPanel(); 30 northPanel.setLayout( new GridLayout( 3, 1, 0, 5 ) ); 31 32 // set up label for NORTH panel 33 label = new JLabel( “This is a Metal look-and-feel”, 34 SwingConstants.CENTER ); 35 northPanel.add( label ); 36 37 // set up button for NORTH panel 38 button = new JButton( “JButton” ); 39 northPanel.add( button ); 40 41 // set up combo box for NORTH panel 42 comboBox = new JComboBox( strings ); 43 northPanel.add( comboBox ); Fig. 13.12 Fig. 13.12 Changing the look-and-feel of a Swing-based GUI (part 1 of 3).
Check Tomcat Web Hosting services for best quality webspace to host your web application.