Archive for July, 2007

Java Swing O Reilly property, but we hesitate (Apache web server for windows)

Friday, July 27th, 2007

Java Swing O Reilly property, but we hesitate to call it a property because its accessor isn’t public. Invoking setUI() by itself, however, does not change the display. A call to updateUI() is also required, which forces the component to redraw itself. If you are looking to change the entire look-and-feel of the application, it is better to change it universally with the setLookAndFeel() method of UIManager, than to change it one component at a time. See Chapter 2 for a simple example of how to work with various look-and-feels. Each Swing component maintains a read-only string constant, UIClassID , that identifies the type of UI delegate that it uses. Most Swing components override the accessor getUIClassID() and return a string constant, typically the letters “UI” appended to the name of the component (without the “J”). This string is then used by Swing’s UI manager to match the component with a UI delegate for the current look-and-feel. For example, a JButton object has a UIClassID string of ButtonUI. If the current look-and-feel is “Metal,” the UIManager can figure out that the MetalButtonUI is the correct UI-delegate class to use. See Chapter 26, for more information about the UIManager and using look-and-feels. 3.3.2.2 Invalidating and Repainting Sometimes entire components need to be drawn to the screen. At other times, only parts of components can (or should) be drawn. For example, if an internal frame is dragged across the container, the entire internal frame is redrawn along the way until it reaches its destination. However, only the parts of the container uncovered by the internal frame need to be repainted. We typically do not repaint the entire component, as this would be an unnecessary waste of processing time. (See Figure 3.4.) Figure 3.4. Performing repaints for components in Java - 56 -
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Java Swing O Reilly focusCycleRoot boolean false focusTraversable

Thursday, July 26th, 2007

Java Swing O Reilly focusCycleRoot boolean false focusTraversable boolean true graphics* Graphics height[1] int bounds.height insets* Insets location* Point Point(bounds.x, bounds.y) managingFocus boolean false maximumSize* Dimension minimumSize* Dimension nextFocusableComponent Component opaque[1] boolean false optimizedDrawingEnabled boolean true paintingTile boolean preferredSize* Dimension registeredKeyStrokes KeyStroke[] requestFocusEnabled boolean true rootPane JRootPane size* Dimension Dimension (bounds.height, bounds.width) toolTipText String null topLevelAncestor Container validateRoot boolean false visible* boolean true visibleRect Rectangle width[1] int bounds.width x[1] int bounds.x y[1] int bounds.y See also java.awt.Container and java.awt.Component (Table 3.4) [1] In JDK 1.2, these properties move to java.awt.Component. 3.3.2.1 UI Delegates and UIClassIDs As we mentioned in Chapter 1, all Swing components use a modified MVC architecture. Each Swing component is responsible for maintaining two unique objects: a model and a UI delegate. The object representing the model handles the state information specific to the component, while the UI delegate determines how the component paints itself based on the model’s state information. Note that there is no property for a model in JComponent. You typically access the model property at the level of a JComponent subclass. This is because each Swing component defines its own data model, unique from all other components. The UI delegate property, on the other hand, can be handled at the JComponent level, because the methods that handle the rendering of lightweight components are always the same. These methods (e.g., installUI(), uninstallUI(), paint()) can be traced back to the abstract class javax.swing.plaf.ComponentUI, which serves as the superclass for all UI delegates. JComponent contains a reference to the current UI delegate for the object. JComponent allows a subclass to alter the component’s UI delegate with the protected setUI() method; this method effectively resets the look-and-feel of the component. The UI therefore acts like a write-only - 55 -
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.

Java Swing (My space web page) O Reilly pack() after you’ve added

Thursday, July 26th, 2007

Java Swing O Reilly pack() after you’ve added components to a top level container with a layout manager, such as JFrame, JApplet, JDialog, and JWindow. public void validate() public void invalidate() The invalidate() method is typically called on a Container to indicate that its children need to be laid out, or on a Component to indicate that it needs to be re-rendered. This method is often called automatically. However, certain changes to a Component (such as changing the size of a button by changing its label or font) do not cause it to be invalidated. In such cases, invalidate() must be called on the Component to mark it as invalid, and validate() must be called on its Container. The validate() method is typically called to cause a Container to be validated, laid out, and repainted. Calling this method is especially important when you add or remove Components in a Container that is already displayed. Swing improves the validate()/invalidate() situation a bit by calling invalidate() in response to many property changes, saving you from having to make the call. Unfortunately, there are still situations (such as changing a JButton’s font) that still do not trigger an automatic invalidate() call, so you’ll still have to explicitly call invalidate() in some situations. The key things to take away from these methods are: You may need to call invalidate() if you make changes to the appearance of a displayed component. You must call validate() on Containers that have been invalidated (typically by the addition or invalidation of a child). As a result of deprecation and the movement toward JavaBeans accessors, AWT has some methods with multiple names. For example, show() and setVisible(true) are essentially the same. It is always better to use the JavaBeans-style name setVisible() when working with Swing; the newer name will be less confusing for people familiar with the JavaBeans conventions. 3.3.2 JComponent Properties Now to the heart of the matter. JComponent has many properties of its own, and overrides (or otherwise modifies) the behavior of many of its inherited properties. This is where the new and interesting stuff happens. Table 3.5 shows a summary of JComponent’s properties. Table 3.5, JComponent Properties Property Data Type get is set bound Default Value UIClassID String “ComponentUI” accessibleContext AccessibleContext null alignmentX* float alignmentY* float autoscrolls boolean false border Border null bounds* Rectangle debugGraphicsOptions int DebugGraphics.NONE_OPTION doubleBuffered boolean false - 54 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Java Swing (Adult web hosting) O Reilly access all of them

Wednesday, July 25th, 2007

Java Swing O Reilly access all of them through a Component array, retrieve the components property. The insets property tells the current insets of the container, while the layout property indicates which layout manager is managing the components of the container. Technically, this means that you can use any component as a container. Don’t be misled; if a component doesn’t seem like a reasonable conainer, it probably can’t be used as one. (Don’t, for example, try to add a JButton to a JScrollBar.) A number of components use these properties for internal, specialized layout managers and components. The locale property specifies the internationalization locale for the application. The location property indicates the x,y coordinates of the component’s upper-left corner in the container’s coordinate space. If you want to see the location of the component’s upper-left corner in screen coordinates, use the read-only locationOnScreen property. The name property gives this component a string-based name that components can display if they choose. The parent property references the container that is acting as this component’s parent, or null if there is none. The size property tells the component’s current height and width in pixels. The showing property indicates whether the component is currently showing on the screen, while the visible property tells if the component is marked to be drawn on the screen. There’s an odd, nonintuitive relationship between visible and showing. A component that is visible isn’t necessarily showing. “Visible” means that a component is capable of being displayed; “showing” means that the component is actually displayed (though it may be obscured by something else). Most containers (JPanel, JFrame, etc.) are invisible by default; most other components (JButton, etc.) are visible by default. So if you add a JButton to an invisible JFrame, for example, the button will be visible but not showing. It’s ready to be displayed, but happens to be in a container that isn’t currently displayed. Finally, if the valid property is false, the component needs to be resized or moved by the component’s layout manager. If it is true, the component is ready to be displayed. 3.3.1.1 Other Methods Here are some other methods you will frequently call when working with Swing components: public Component add(Component comp) public Component add(Component comp, int index) public void add(Component comp, Object constraints) public void add(Component comp, Object constraints, int index) Add a component to the container, given the optional constraints and the current index. public void remove(int index) public void remove(Component comp) public void removeAll() Remove the appropriate component from the container. The final method empties the entire container. public void pack() This method of java.awt.Window resizes the window to encompass the preferred size of all the contained components, as placed by the current layout manager. It’s a good idea to call - 53 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Java Swing O Reilly Because all Swing components

Wednesday, July 25th, 2007

Java Swing O Reilly Because all Swing components extend Container, you should be careful that you don’t to Swing components that aren’t truly containers. The results can range from amusing to destructive. In JDK 1.2, JComponent reuses some of the functionality of the java.awt.Graphics2D class. This consists primarily of responsibilities for component painting and debugging. 3.3.1 Inherited Properties Swing components carry with them several properties that can be accessed through JComponent, but otherwise originate with AWT. Before we go any further, we should review those properties of java.awt.Container and java.awt.Component that can be used to configure all Swing components. This discussion is relatively brief; if you need a more thorough explanation of these AWT classes, see our sister book Java AWT by John Zukowski (O’Reilly). Table 3.4 lists the properties that JComponent inherits from its AWT superclasses. Table 3.4, Properties Inherited from the AWT Component and Container Classes Property Data Type get is set bound Default Value background Color colorModel ColorModel component (indexed) Component componentCount int components Component[] cursor Cursor Cursor.DEFAULT_CURSOR enabled boolean true font Font foreground Color insets Insets Insets(0,0,0,0) layout LayoutManager BorderLayout() locale Locale location Point locationOnScreen Point name String “” parent Container null size Dimension showing boolean true valid boolean visible boolean true Let’s briefly discuss these properties. The background and foreground properties indicate which colors the component will use to paint itself. We should mention that with Swing the backgroundproperty will be disabled if the component is transparent (not opaque). The read-only colorModel property returns the current model used to translate colors to pixel values; the user generally does not need to access this property. The font property lets you get or set the font used for displaying text in the component. The indexed component property maintains a list of all the components inside the container. You can tell how many there are through the use of the integer componentCount property. If you want to - 52 -
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.

Christian web host - Java Swing O Reilly The constructor for the

Tuesday, July 24th, 2007

Java Swing O Reilly The constructor for the ChangeEvent class. It takes only a single object, which represents the entity sending the event. The ChangeEvent class extends the java.util.EventObject class. This object contains the getSource() method, which you can use to access the source object that fired the event. 3.2.2 The ChangeListener Interface Objects that intend to receive change events must implement the com.sun.java. swing.event.ChangeListener interface. They can then register to receive ChangeEvent objects from a publisher class. The ChangeListener interface only consists of one method: 3.2.2.1 Method public abstract void stateChanged(ChangeEvent e) Implemented in a listener object to receive ChangeEvent notifications. 3.3 The JComponent Class JComponent is an abstract class that almost all Swing components extend; it provides much of the underlying functionality common throughout the Swing component library. Just as the java.awt.Component class serves as the guiding framework for most of the AWT components, the javax.swing.JComponent class serves an identical role for the Swing components. We should note that the JComponent class extends java.awt.Container (which in turn extends java.awt.Component), so it is accurate to say that Swing components carry with them a great deal of AWT functionality as well. Because JComponent extends Container, many Swing components can serve as containers for other AWT and Swing components. These components may be added using the traditional add() method of Container. In addition, they can be positioned with any Java layout manager while inside the container. The terminology remains the same as well: components that are added to a container are said to be its children; the container is the parent of those components. Following the analogy, any component that is higher in the tree is said to be its ancestor, while any component that is lower is said to be its descendant. Recall that Swing components are considered “lightweight.” In other words, they do not rely on corresponding peer objects within the operating system to render themselves. As we mentioned in Chapter 1, lightweight components draw themselves using the standard features of the abstract Graphics object, which not only decreases the amount of memory each component uses, but allows components to have transparent portions and take on nonrectangular shapes. And, of course, lightweight components are free from a dedicated look-and-feel. It’s not out of the question to say that a potential benefit of using lightweight components is a decrease in testing time. This is because the functionality necessary to implement lightweight components in the Java virtual machine is significantly less than that of heavyweight components. Heavyweight components must be individually mapped to their own native peers. On the other hand, one need only implement a single lightweight peer on each OS for all the Swing components to work correctly. Hence, there is a far greater chance that lightweight components will execute as expected on any operating system and not require rounds of testing for each platform. - 51 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing (My web site) O Reilly Action [Download] performed! Now

Tuesday, July 24th, 2007

Java Swing O Reilly Action [Download] performed! Now for something interesting. You can add the following line to the constructor to disable the action: exampleAction.setEnabled(false); With this line, the PropertyChangeEvent propagates to listeners in the menu item and in the toolbar button, causing both components to turn gray and become disabled. Figure 3.3 shows what happens when an action is disabled. Figure 3.3. A disabled action in a menu and in a toolbar Of course, you can enable the menu item and toolbar button again at any time with the following line of code: exampleAction.setEnabled(true); Upon execution, the property change again propagates, re-enabling both components simultaneously. 3.2 Sending Change Events in Swing Swing actually uses two different change event classes. The first is the standard java.beans.PropertyChangeEvent class. This class passes a reference to the object, sending the change notification, as well as the property name, its old value, and its new value. The second, javax. swing.event.ChangeEvent, is a lighter version that only passes a reference to the sending object in other words, the name of the property that changed, as well as the old and new values, are omitted. Since the class is not part of the JavaBeans specifications, properties that use this event are not “bound” according to the JavaBeans standard. In order to prevent confusion, properties that use a to notify listeners of property changes have not been marked as bound in our property tables. Because the ChangeEvent only includes a reference to the event originator, which never changes, you can always define a single, static ChangeEvent and reuse it over and over when firing events from your component. 3.2.1 The ChangeEvent Class The ChangeEvent is a stripped-down version of the java.beans.PropertyChangeEvent class. This class has no methods or properties, only a constructor: 3.2.1.1 Constructor public ChangeEvent(Object source) - 50 -
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Java Swing (Web site traffic) O Reilly // Create a toolbar

Monday, July 23rd, 2007

Java Swing O Reilly // Create a toolbar and give it an etched border toolBar = new JToolBar(); toolBar.setBorder(new EtchedBorder()); // Instantiate a sample action with the NAME property of// “Download” and the appropriate SMALL_ICON propertySampleAction exampleAction = new SampleAction(”Download”, new ImageIcon(”action.gif”)); // Finally, add the sample action to the menu and the toolbar. menu.add(exampleAction); toolBar.add(exampleAction); } class SampleAction extends AbstractAction { // This is our sample action. It must have an actionPerformed() method, // which is called when the action should be invoked. public SampleAction(String text, Icon icon) { super(text,icon); } public void actionPerformed(ActionEvent e) { System.out.println(”Action [” + e.getActionCommand() + “] performed!”); } } public static void main(String s[]) { ActionExample example = new ActionExample(); JFrame frame = new JFrame(”Action Example”); frame.addWindowListener(new BasicWindowMonitor()); frame.setJMenuBar(example.menuBar); frame.getContentPane().add(example.toolBar, BorderLayout.NORTH); frame.setSize(200,200); frame.setVisible(true); } } The preceding example creates a toolbar with a single button and a menu with a single menu item. Both are generated from the SampleAction class, and are shown in Figure 3.2. Note that we used the BasicWindowMonitor that we developed in Chapter 2, inside our main() function to close the window properly. Figure 3.2. An action in a menu and in a toolbar Selecting the menu item or clicking on the toolbar button a few times both yield the same results to the console: Action [Download] performed! Action [Download] performed! - 49 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing O Reilly protected javax.swing.event.PropertyChangeSupport changeSupport Manages (Web hosting domain names)

Monday, July 23rd, 2007

Java Swing O Reilly protected javax.swing.event.PropertyChangeSupport changeSupport Manages the change listeners for the AbstractAction. Event-related methods in this class typically call upon their PropertyChangeSupport equivalents here. Notice that Swing is using its own PropertyChangeSupport class in JDK 1.2/Swing 1.1. In Swing 1.0, it used the PropertyChangeSupport class from java.beans. 3.1.3.4 Constructors public AbstractAction() public AbstractAction(String name) public AbstractAction(String name, Icon icon) The constructors for the AbstractAction object can be used to set the name and icon hashtable properties of the action under the NAME or SMALL_ICON keys, respectively. 3.1.3.5 Methods public Object getValue(String key) public void putValue(String key, Object value) Store or retrieve various elements in a private Hashtable. A string-based key is used to index the Hashtable values. See the Action interface earlier in the chapter for an enumeration of common string-based keys. 3.1.3.6 Using an Action This example creates an Action for both a menu item and a toolbar, displaying both components and allowing the user to click on either one. When the components are clicked, the actionPerformed() method of the action is called. Don’t worry if you don’t understand all the methods behind the toolbar or the menu; these classes will be discussed later. For now, it is important to see that selecting either one performs the action. // ActionExample.java // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class ActionExample extends JPanel { public JMenuBar menuBar; public JToolBar toolBar; public ActionExample() { super(true); // Create a menu bar and give it a bevel border menuBar = new JMenuBar(); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); // Create a menu and add it to the menu bar JMenu menu = new JMenu(”Menu”); menuBar.add(menu); - 48 -
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Managed web hosting - Java Swing O Reilly you must provide an

Monday, July 23rd, 2007

Java Swing O Reilly you must provide an implementation is the actionPerformed() method. This method is where you provide the functionality for the action. Here is a simple example: class MyAction extends AbstractAction { public MyAction(String text, Icon icon) { super(text,icon); } public void actionPerformed(ActionEvent e) { System.out.println(”Action [”+e.getActionCommand()+”]!”); } } Here, we simply print out the action command that was sent with the ActionEvent. You can add more features based on the contents of the ActionEvent. 3.1.3.1 Properties The AbstractAction class stores its keyed properties in a Hashtable object. Beyond that, the AbstractAction object contains a single property, as shown in Table 3.3. The enabled property defines whether the application can invoke the action. When this property changes, AbstractAction fires a PropertyChangeEvent. The set accessor for this property, setEnabled() is synchronized. Table 3.3, AbstractAction Properties Property Data Type get is set bound Default Value enabled * boolean true 3.1.3.2 Events The AbstractAction class fires a PropertyChangeEvent when any property in the hashtable is changed or when the action is enabled or disabled. public synchronized void addPropertyChangeListener(PropertyChangeListener listener) public synchronized void removePropertyChangeListener(PropertyChangeListener listener) Add or remove the specified PropertyChangeListener from the event listener list. protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) Notifies all registered listeners that a property change has occurred in the action. It specifies the name of the property, as well as the old and new values. 3.1.3.3 Protected Fields The following are protected fields in the AbstractAction class: protected boolean enabled Defines whether the action is enabled or disabled. - 47 -
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.