Archive for July, 2007

788 Graphical User Interface Components: Part (Apache web server tutorial) 2 Chapter

Tuesday, July 31st, 2007

788 Graphical User Interface Components: Part 2 Chapter 13 32 33 // register View for Model events 34 model.setElevatorModelListener( view ); 35 36 // add view and controller to ElevatorSimulation 37 getContentPane().add( view, BorderLayout.CENTER ); 38 getContentPane().add( controller, BorderLayout.SOUTH ); 39 40 } // end ElevatorSimulation constructor 41 42 // main method starts program 43 public static void main( String args[] ) 44 { 45 // instantiate ElevatorSimulation 46 ElevatorSimulation simulation = new ElevatorSimulation(); 47 simulation.setDefaultCloseOperation( EXIT_ON_CLOSE ); 48 simulation.pack(); 49 simulation.setVisible( true ); 50 } 51 } Fig. 13.21 Class ElevatorSimulationis the application for the elevator simulation (part 2 of 2). The class diagram of Fig. 13.19 specifies that class ElevatorSimulation is a subclass of javax.swing.JFrame line 16 declares class ElevatorSimulation as a public class extending class JFrame. Lines 19 21 implement class Elevator- Simulation s aggregation of class ElevatorModel, the ElevatorView and the ElevatorController (shown in Fig. 13.19) by declaring one object from each class. Lines 29 31 of the ElevatorSimulationconstructor initialize these objects. Figure 13.19 and Fig. 13.20 specify that the ElevatorViewis an ElevatorModelListenerfor the ElevatorModel. Line 34 registers the ElevatorViewas a listener for ElevatorModelEvents, so the ElevatorViewcan receive events from the ElevatorModel and properly represent the state of the model. Lines 37 38 add the ElevatorView and the ElevatorController to the ElevatorSimulation. According to the stereotypes in Fig. 13.20, ElevatorSimulation.javacompiles to ElevatorSimulation.class, which is executable lines 43 50 provide method mainthat runs the application. We have completed the design of the components of our system. Thinking About Objects Section 15.12 concludes the design of the model by solving the interaction problems encountered in Fig. 10.26. Finally, Section 22.9 completes the design of the view and describes in greater detail how the ElevatorView receives events from the ElevatorModel. These last two sections will prepare you for the walkthrough of our elevator- simulation implementation in Appendices G, H and I. 13.18 (Optional) Discovering Design Patterns: Design Patterns Used in Packages java.awtand javax.swing We continue our discussion from Section 9.24 on design patterns. This section introduces those design patterns associated with Java GUI components. After reading this section, you
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web hosting domain - Chapter 13 Graphical User Interface Components: Part 2

Tuesday, July 31st, 2007

Chapter 13 Graphical User Interface Components: Part 2 787 According to Fig. 13.20, ElevatorModel.javaand ElevatorView.javado not depend on each other they communicate through interface ElevatorModelListener, which implements all interfaces in the simulation. ElevatorView.javarealizes interface ElevatorModelListener, and ElevatorModel.javadepends on interface ElevatorModelListener. Figure 13.20 contains several stereotypes words placed in guillemets ( ) indicating an element s role. We mentioned the interface stereotype in Thinking About Objects Section 11.10. The compilation stereotype describes the dependency between ElevatorSimulation.class and ElevatorSimulation.java ElevatorSimulation.javacompiles to ElevatorSimulation.class. The executable stereotype specifies that a component is an application, and the file stereotype specifies that a component is a file containing source code for the executable. Implementation: ElevatorSimulation.java We use the component diagram of Fig. 13.20, the class diagram of Fig. 13.19 and the use- case diagram of Fig. 12.28 to implement ElevatorSimulation.java (Fig. 13.21). Lines 12 14 import packages model, viewand controlleras specified in Fig. 13.20. 1 // ElevatorSimulation.java 2 // Application with Elevator Model, View, and Controller (MVC) 3 package com.deitel.jhtp4.elevator; 4 5 // Java core packages 6 import java.awt.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 // Deitel packages 12 import com.deitel.jhtp4.elevator.model.*; 13 import com.deitel.jhtp4.elevator.view.*; 14 import com.deitel.jhtp4.elevator.controller.*; 15 16 public class ElevatorSimulation extends JFrame { 17 18 // model, view and controller 19 private ElevatorModel model; 20 private ElevatorView view; 21 private ElevatorController controller; 22 23 // constructor instantiates model, view, and controller 24 public ElevatorSimulation() 25 { 26 super( “Deitel Elevator Simulation” ); 27 28 // instantiate model, view and controller 29 model = new ElevatorModel(); 30 view = new ElevatorView(); 31 controller = new ElevatorController( model ); Fig. 13.21 Class ElevatorSimulationis the application for the elevator simulation (part 1 of 2).
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

786 Graphical User Interface Components: Part 2 Chapter (Web server application)

Monday, July 30th, 2007

786 Graphical User Interface Components: Part 2 Chapter 13 relationship between components in which changes in one component affect another component. For example, component ElevatorSimulation.class depends on component ElevatorSimulation.java, because a change in ElevatorSimulation.java affects ElevatorSimulation.classwhen ElevatorSimulation.javais compiled. Section 12.16 mentioned that the ElevatorController object contains a reference to the ElevatorModel object (to place Persons on Floors). Therefore, ElevatorController.javadepends on ElevatorModel.java. Software Engineering Observation 13.8 A component diagram s dependencies help designers group components for reuse in future systems. For example, in our simulation, designers can reuse ElevatorModel.javain other systems without having to reuse ElevatorView.java(and vice versa), because these components do not depend on each other. However, if a designer wanted to reuse Elevator- Controller.java, the designer would have to reuse ElevatorModel.java. ElevatorSimulation.class view controller model ElevatorSimulation.java compilation 1 1 1 1 1 executable file ElevatorModel.java file ElevatorView.java file ElevatorController.java file ElevatorModel- Listener 1 Fig. 13.20Component diagram for elevator simulation. 13.20
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Unable to start debugging on the web server - Chapter 13 Graphical User Interface Components: Part 2

Monday, July 30th, 2007

Chapter 13 Graphical User Interface Components: Part 2 785 We showed in Fig. 9.38 that class ElevatorModel is an aggregation of several classes. To save space, we do not repeat this aggregation in Fig. 13.19. Class Elevator- Viewis also an aggregation of several classes we expand the class diagram of ElevatorView in Thinking About Objects Section 22.9 to show these additional classes. Class ElevatorController, as described in Section 12.16, represents the simulation controller. Note that class ElevatorView implements interface ElevatorModel- Listener, which implements all interfaces used in our simulation, so the Elevator- View can receive all events from the model. Software Engineering Observation 13.7 When appropriate, partition the system class diagram into several smaller class diagrams, so each diagram represents a unique subsystem. Class ElevatorSimulation contains no attributes other than its references to an ElevatorModel object, an ElevatorView object and an ElevatorController object. The only behavior for class ElevatorSimulation is to start the program therefore, in Java, class ElevatorSimulation contains a staticmain method that calls the constructor, which instantiates the ElevatorModel, ElevatorView and ElevatorController objects. We implement class ElevatorSimulation in Java later in this section. Component Diagrams Figure 13.19 helps us construct another diagram of the UML that we use to design our system the component diagram. The component diagram models the pieces called components that the system needs to perform its tasks. These pieces include binary executables, compiled .class files, .java files, images, packages, resources, etc. We present the component diagram for our simulation in Fig. 13.20. In Fig. 13.20, each box that contains the two small white boxes overlapping its left side is a component. A component in the UML is drawn similar to a plug (the two overlapping boxes represent the plug s prongs) a component may be plugged-in to other systems without having to change the component. Our system contains five components: ElevatorSimulation.class, ElevatorSimulation.java, Elevator- Model.java, ElevatorView.java and ElevatorController.java. In Fig. 13.20, the graphics that resemble folders (boxes with tabs in their upper-left corners) represent packages in the UML. We can group classes, objects, components, use cases, etc., in a package. In this diagram (and in the remainder of our case study), the UML packages refer to Java packages (introduced in Section 8.5). In our discussion, we use lower-case bold-face Courier type for package names. The packages in our system are model, view and controller. Component ElevatorSimulation.java contains one instance each of all components in these packages. Currently, each package contains only one component a .java file. The model package contains ElevatorModel.java, the view package contains ElevatorView.java and the controller package contains ElevatorController.java. We add components to each package in the appendices, when we implement each class from our class diagrams into a component (.java file). The dotted arrows in Fig. 13.20 indicate a dependency between two components the direction of the arrow indicates the depends on relationship. A dependency describes the
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Make my own web site - 784 Graphical User Interface Components: Part 2 Chapter

Sunday, July 29th, 2007

784 Graphical User Interface Components: Part 2 Chapter 13 Fig. 2.24). The model then notifies the view of the Person s creation. The view, in response to this notification, displays a Person on a Floor. The model is unaware of how the view displays the Person, and the view is unaware of how or why the model created the Person. The MVC architecture helps construct reliable and easily modifiable systems. If we desire text-based output rather than graphical output for the elevator simulation, we may create an alternate view to produce text-based output, without altering the model or the controller. We could also provide a three-dimensional view that uses a first-person perspective to allow the user to take part in the simulation; such views are commonly employed in virtual-reality-based systems. Elevator-Simulation MVC We now apply the MVC architecture to our elevator simulation. Every UML diagram we have provided to this point (with the exception of the use-case diagram) relates to the model of our elevator system. We provide a higher-level class diagram of the simulation in Fig. 13.19. Class ElevatorSimulation a JFrame subclass aggregates one instance each of classes ElevatorModel, ElevatorViewand ElevatorController to create the ElevatorSimulation application. As mentioned in Thinking About Objects Section 10.22, the rectangle with the upper-right corner folded over represents a note in the UML. In this case, each note points to a specific class (through a dotted line) to describe that class role in the system. Classes ElevatorModel, Elevator- View and ElevatorControllerencapsulate all objects comprising the model, view and controller portions of our simulation, respectively. ElevatorSimulation 1 1 1 1 application ElevatorModel ElevatorView javax.swing.JFrame ElevatorController 1 1 ElevatorModelListener controllerviewmodel Fig. 13.19Class diagram of the elevator simulation. 13.19
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 (Web hosting comparison)

Sunday, July 29th, 2007

Chapter 13 Graphical User Interface Components: Part 2 783 JButton buttons[0] (lines 53 54) has weightx and weighty values of 1. The fill variable is BOTH. Because buttons[0] is not one of the last two components on the row, it is given a gridwidth of 1 so it will occupy one column. The JButton is added to the content pane with a call to utility method addComponent. JButtonbuttons[1] (lines 57 58) has weightx and weighty values of 1. The fill variable is BOTH. Line 57 specifies that the JButton is to be placed relative to the previous component. The Button is added to the JFrame with a call to addComponent. JButton buttons[2] (lines 61 62) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the last component on the line, so REMAINDER is used. The JButton is added to the content pane with a call to utility method addComponent. The JComboBox button (lines 65 67) has a weightx 1 and a weighty 0. The JComboBox will not grow in the vertical direction. The JComboBoxis the only component on the line, so REMAINDER is used. The JComboBox is added to the content pane with a call to utility method addComponent. JButton buttons[3] (lines 70 72) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the only component on the line, so REMAINDER is used. The JButton is added to the content pane with a call to utility method addComponent. JButton buttons[4] (lines 75 76) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the next-to-last component on the line, so RELATIVE is used. The JButton is added to the content pane with a call to utility method addComponent. The JList component (lines 79 80) has weightx and weighty values of 1. The fill variable is BOTH. The JList is added to the content pane with a call to utility method addComponent. 13.17 (Optional Case Study) Thinking About Objects: Model- View-Controller Design patterns describe proven strategies for building reliable object-oriented software systems. Our case study adheres to the Model-View-Controller (MVC) architecture, which uses several design patterns.1 MVC divides system responsibilities into three parts: 1. the model, which contains all program data and logic; 2. the view, which provides a visual presentation of the model and 3. the controller, which defines the system behavior by sending user input to the model. Using the controller, the user changes the data in the model. The model then informs the view of the change in data. The view changes its visual presentation to reflect the changes in the model. For example, in our simulation, the user adds a Person to the model by pressing either the First Floor or Second Floor JButton in the controller (see Fig. 2.22 1. For those readers who seek further study in design patterns and MVC architecture, we encourage you to read our Discovering Design Patterns material in Sections 1.16, 9.24, 13.18, 15.13, 17.11 and 21.12
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Web host - 782 Graphical User Interface Components: Part 2 Chapter

Saturday, July 28th, 2007

782 Graphical User Interface Components: Part 2 Chapter 13 77 78 // list –weightx and weighty are 1: fill is BOTH 79 constraints.gridwidth = GridBagConstraints.REMAINDER; 80 addComponent( list ); 81 82 setSize( 300, 200 ); 83 setVisible( true ); 84 85 } // end constructor 86 87 // addComponent is programmer-defined 88 private void addComponent( Component component ) 89 { 90 layout.setConstraints( component, constraints ); 91 container.add( component ); // add component 92 } 93 94 // execute application 95 public static void main( String args[] ) 96 { 97 GridBagDemo2 application = new GridBagDemo2(); 98 99 application.setDefaultCloseOperation( 100 JFrame.EXIT_ON_CLOSE ); 101 } 102 103 } // end class GridBagDemo2 Fig. 13.21 Demonstrating the GridBagConstraintsconstants RELATIVEand REMAINDER(part 3 of 3). Lines 22 23 construct a GridBagLayoutand set the content pane s layout manager to GridBagLayout. The components that are placed in GridBagLayoutare each constructed (lines 29 42). The components are five JButtons, one JTextField, one JListand one JComboBox. The JTextFieldis added first (lines 46 50). The weightxand weightyvalues are set to 1. The fillvariable is set to BOTH. Line 49 specifies that the JTextFieldis the last component on the line. The JTextFieldis added to the content pane with a call to our utility method addComponent(defined at lines 88 92). Method addComponent takes a Componentargument and uses GridBagLayoutmethod setConstraints to set the constraints for the Component. Method addattaches the component to the content pane.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Chapter 13 Graphical User Interface Components: (My space web page) Part 2

Saturday, July 28th, 2007

Chapter 13 Graphical User Interface Components: Part 2 781 25 // instantiate gridbag constraints 26 constraints = new GridBagConstraints(); 27 28 // create GUI components 29 String metals[] = { “Copper”, “Aluminum”, “Silver” }; 30 JComboBox comboBox = new JComboBox( metals ); 31 32 JTextField textField = new JTextField( “TextField” ); 33 34 String fonts[] = { “Serif”, “Monospaced” }; 35 JList list = new JList( fonts ); 36 37 String names[] = 38 { “zero”, “one”, “two”, “three”, “four” }; 39 JButton buttons[] = new JButton[ names.length ]; 40 41 for ( int count = 0; count < buttons.length; count++ ) 42 buttons[ count ] = new JButton( names[ count ] ); 43 44 // define GUI component constraints 45 // textField 46 constraints.weightx = 1; 47 constraints.weighty = 1; 48 constraints.fill = GridBagConstraints.BOTH; 49 constraints.gridwidth = GridBagConstraints.REMAINDER; 50 addComponent( textField ); 51 52 // buttons[0] -- weightx and weighty are 1: fill is BOTH 53 constraints.gridwidth = 1; 54 addComponent( buttons[ 0 ] ); 55 56 // buttons[1] -- weightx and weighty are 1: fill is BOTH 57 constraints.gridwidth = GridBagConstraints.RELATIVE; 58 addComponent( buttons[ 1 ] ); 59 60 // buttons[2] -- weightx and weighty are 1: fill is BOTH 61 constraints.gridwidth = GridBagConstraints.REMAINDER; 62 addComponent( buttons[ 2 ] ); 63 64 // comboBox --weightx is 1: fill is BOTH 65 constraints.weighty = 0; 66 constraints.gridwidth = GridBagConstraints.REMAINDER; 67 addComponent( comboBox ); 68 69 // buttons[3] -- weightx is 1: fill is BOTH 70 constraints.weighty = 1; 71 constraints.gridwidth = GridBagConstraints.REMAINDER; 72 addComponent( buttons[ 3 ] ); 73 74 // buttons[4] -- weightx and weighty are 1: fill is BOTH 75 constraints.gridwidth = GridBagConstraints.RELATIVE; 76 addComponent( buttons[ 4 ] ); Fig. 13.21 Demonstrating the GridBagConstraintsconstants RELATIVEand REMAINDER(part 2 of 3).
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

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

Friday, July 27th, 2007

780 Graphical User Interface Components: Part 2 Chapter 13 grow if the window is resized; it is affected by the weight values of button2. Note that the weightx value for button2 is much larger than button3. When resizing occurs, button2will occupy a larger percentage of the new space. The button is placed at row 1, column 2. One row and one column are occupied. Both the JTextField (line 70) and JTextArea textArea2 (line 74) have a weightx value 0 and a weighty value 0. The value of fill is BOTH. The JText- Field is placed at row 3, column 0, and the JTextArea is placed at row 3, column 2. The JTextField occupies one row and two columns. The JTextArea occupies one row and one column. When you execute this application, try resizing the window to see how the constraints for each GUI component affect its position and size in the window. 13.16 GridBagConstraintsConstants RELATIVEand REMAINDER A variation of GridBagLayout does not use gridx and gridy. Rather, Gridbag- Constraints constants RELATIVE and REMAINDER are used in their place. RELATIVE specifies that the next-to-last component in a particular row should be placed to the right of the previous component in that row. REMAINDERspecifies that a component is the last component in a row. Any component that is not the second-to-last or last component on a row must specify values for GridbagConstraints variables gridwidth and gridheight. Class GridBagDemo2in Fig. 13.21 arranges components in GridBag- Layout, using these constants. 1 // Fig. 13.21: GridBagDemo2.java 2 // Demonstrating GridBagLayout constants. 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 GridBagDemo2 extends JFrame { 12 private GridBagLayout layout; 13 private GridBagConstraints constraints; 14 private Container container; 15 16 // set up GUI 17 public GridBagDemo2() 18 { 19 super( “GridBagLayout” ); 20 21 container = getContentPane(); 22 layout = new GridBagLayout(); 23 container.setLayout( layout ); 24 Fig. 13.21 Demonstrating the GridBagConstraintsconstants RELATIVEand REMAINDER(part 1 of 3).
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Chapter 13 Graphical User Interface (Domain and web hosting) Components: Part 2

Friday, July 27th, 2007

Chapter 13 Graphical User Interface Components: Part 2 779 of each component in the grid is instantiated with line 26. Lines 23 through 30 instantiate each of the GUI components that will be added to the content pane. JTextArea textArea1 is the first component added to the GridBagLayout (line 44). The values for weightx and weighty values are not specified in gbConstraints, so each has the value zero by default. Thus, the JTextArea will not resize itself even if space is available. However, the JTextAreaspans multiple rows, so the vertical size is subject to the weighty values of JButtons button2 and button3. When either button2 or button3 is resized vertically based on its weighty value, the JTextArea is also resized. Line 43 sets variable fillin constraintsto GridBagConstraints.BOTH, causing the JTextArea to always fill its entire allocated area in the grid. An anchor value is not specified in constraints, so the default CENTER is used. We do not use variable anchor in this program, so all components will use the default. Line 36 calls our utility method addComponent method (defined at lines 81 95). The JTextArea object, the row, the column, the number of columns to span and the number of rows to span are passed as arguments. Method addComponent s parameters are a Component reference component and integers row, column, width and height. Lines 85 86 set the GridBagConstraints variables gridx and gridy. The gridx variable is assigned the column in which the Component will be placed, and the gridy value is assigned the row in which the Component will be placed. Lines 89 90 set the GridBagConstraints variables gridwidth and gridheight. The gridwidthvariable specifies the number of columns the Component will span in the grid and the gridheight variable specifies the number of rows the Component will span in the grid. Line 93 sets the GridBagConstraints for a component in the GridBagLayout. Method setConstraints of class GridBagLayout takes a Component argument and a GridBagConstraints argument. Method add (line 94) is used to add the component to the content pane. JButton object button1 is the next component added (lines 48 49). The values of weightx and weighty are still zero. The fill variable is set to HORIZONTAL the component will always fill its area in the horizontal direction. The vertical direction is not filled. The weighty value is zero, so the button will become taller only if another component in the same row has a nonzero weighty value. JButton b1 is located at row 0, column 1. One row and two columns are occupied. JComboBox comboBox is the next component added (line 54). The weightx and weighty values are zero, and the fill variable is set to HORIZONTAL. The JComboBox button will grow only in the horizontal direction. Note that the weightx, weighty and fill variables remain set in gbConstraints until they are changed. The JComboBox button is placed at row 2, column 1. One row and two columns are occupied. JButton object button2 is the next component added (lines 57 60). JButton button2 is given a weightx value of 1000 and a weighty value of 1. The area occupied by the button is capable of growing in the vertical and horizontal directions. The fill variable is set to BOTH, which specifies that the button will always fill the entire area. When the window is resized, b2 will grow. The button is placed at row 1, column 1. One row and one column are occupied. JButton button3 is added next (lines 64 66). Both the weightx value and weighty value are set to zero, and the value of fillis BOTH. JButtonbutton3 will
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.