Chapter 13 Graphical User Interface Components: Part 2 (Php web hosting)
Chapter 13 Graphical User Interface Components: Part 2 795 tainer object s method setLayout to assign the FlowLayout object to the Containerobject. In this example, the FlowLayout provides the strategy for laying out the components. Template Method The Template Method design pattern also deals with algorithms. The Strategy design pattern allows several objects to contain distinct algorithms. However, the Template Method design pattern requires all objects to share a single algorithm defined by a superclass. For example, consider the design of Fig. 13.23, which we mentioned in the Observer design pattern discussion. Objects of classes TextDisplay, BarGraphDisplay and PieChartDisplay use the same basic algorithm for acquiring and displaying the data get all statements from the BankStatementData object, parse the statements then display the statements. The Template Method design pattern allows us to create an abstract superclass called BankStatementDisplay that provides the central algorithm for displaying the data. In this example, the algorithm comprises abstract methods get- Data, parseData and displayData comprise the algorithm. Classes TextDisplay, BarGraphDisplay and PieChartDisplay extend class BankStatementDisplay to inherit the algorithm, so each object can use the same algorithm. Each BankStatementDisplay subclass then overrides each method in a way specific to that subclass, because each class implements the algorithm differently from one another. For example, classes TextDisplay, BarGraphDisplay and Pie- ChartDisplay might get and parse the data identically, but each class displays that data differently. The Template Method design pattern allows us to extend the algorithm to other Bank- StatementDisplay subclasses e.g., we could create classes, such as LineGraph- Display or class 3DimensionalDisplay, that use the same algorithm inherited from class BankStatementDisplay. 13.18.4 Conclusion In this Discovering Design Patterns section, we discussed how Swing components take advantage of design patterns and how developers can integrate design patterns with GUI applications in Java. In Discovering Design Patterns Section 15.13, we discuss concurrency design patterns, which are particularly useful for developing multithreaded systems. SUMMARY JTextAreas provide an area for manipulating multiple lines of text. Like class JTextField, class JTextArea inherits from JTextComponent. An external event (i.e., an event generated by a different GUI component) normally indicates when the text in a JTextArea should be processed. Scrollbars are provided for a JTextArea by attaching it to a JScrollPaneobject. Method getSelectedTextreturns the selected text from a JTextArea. Text is selected by dragging the mouse over the desired text to highlight it. Method setText sets the text in a JTextArea. To provide automatic word wrap in a JTextArea, attach it to a JScrollPane with horizontal scrollbar policy JScrollPane.HORIZONTAL_SCROLLBAR_NEVER.
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services