Tech all over the world
Thursday, May 04, 2006
  Java Technology Fundamentals Newsletter

You are receiving this e-mail {e-mail address} because you elected to receive e-mail from Sun Microsystems, Inc. To update your communications preferences, please see the link at the bottom of this message. We respect your privacy and post our privacy policy prominently on our Web site http://sun.com/privacy/

Please do not reply to the mailed version of the newsletter, this alias is not monitored. Feedback options are listed in the footer for both content and delivery issues.
  Welcome to the Java Technology Fundamentals Newsletter.
Java Technology Fundamentals
NEWSLETTER
May 2006
 
This monthly newsletter provides a way for you to learn the basics of the Java programming language, discover new resources, and keep up-to-date on the latest additions to Sun Developer Network's New to Java Center.

You can receive future issues of this newsletter in HTML or text:
http://developer.java.sun.com/subscription/

Note: For the code in this issue of Fundamentals to compile, you need to use the JDK 5.0 software.
http://java.sun.com/j2se/1.5.0/download.jsp

Contents
 
» Java Programming Language Basics: Getting to Know JColorChooser
» Making Sense of the Java Classes & Tools: Using Java DB in Desktop Applications
» Java Bits: J2SE FAQ
» What's New on Java Studio Creator: Using the File Upload Component
» Tutorials and Tips From NetBeans.org: NetBeans IDE 5.0 HTML Editor Tutorial
» Applet Deployment Guide for Microsoft Internet Explorer
» Sun's Technology Courses
» Free Developer Tools
» For More Information

Java Programming Language Basics
 
Getting to Know JColorChooser


The JColorChooser is an option pane for selection of a Color object. It is not a ready-to-use popup window, but instead a bunch of components in a container. Here is what a JColorChooser might look like in your own application window.

Basic

At the top are three selectable color chooser panels, the tabs; at the bottom is a preview panel, the part labeled Preview. The "I Love Swing" bit is not part of the chooser, but instead of the application that contains the chooser. Notice there are no buttons, they are not part of the chooser.

In addition to appearing within your application windows, the JColorChooser class also provides support methods for automatically placing the group of components in a JDialog. Here is one such automatically created popup.

Popup

If you want to create a JColorChooser and place it in your own window, you'd use one of the three constructors for the JColorChooser class. By default, the initial color for the chooser is white. If you don't want white as the default, you can provide the initial color as a Color object (or ColorSelectionModel). The different constructors follow, along with a sample creation usage.

  • public JColorChooser()
    JColorChooser colorChooser = new JColorChooser();
  • public JColorChooser(Color initialColor)
    JColorChooser colorChooser =
    new JColorChooser(aComponent.getBackground());
  • public JColorChooser(ColorSelectionModel model)
    JColorChooser colorChooser =
    new JColorChooser(aColorSelectionModel);

Once you've created a JColorChooser from a constructor, you can place it in any Container, just like any other Component. For instance, the following source created the last screen shown.

 import java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.colorchooser.*;  public class ColorSample {    public static void main(String args[]) {     Runnable runner = new Runnable() {       public void run() {         JFrame frame = new JFrame("JColorChooser Popup");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          final JLabel label = new JLabel("I Love Swing", JLabel.CENTER);         label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));         frame.add(label, BorderLayout.SOUTH);          final JColorChooser colorChooser =           new JColorChooser(label.getBackground());         colorChooser.setBorder(           BorderFactory.createTitledBorder("Pick Foreground Color"));          // More source to come         frame.add(colorChooser, BorderLayout.CENTER);          frame.pack();         frame.setVisible(true);       }     };     EventQueue.invokeLater(runner);   } } 

Although this source code creates the GUI, selecting a different color within the JColorChooser doesn't do anything yet. Let's now add the code that causes color changes.

The JColorChooser uses a ColorSelectionModel as its data model. As the following interface definition shows, the data model includes a single property, selectedColor, for managing the state of the color chooser.

 public interface ColorSelectionModel {   // Listeners   public void addChangeListener(ChangeListener listener);   public void removeChangeListener(ChangeListener listener);   // Properties   public Color getSelectedColor();   public void setSelectedColor(Color newValue); } 

When a user changes the color within the JColorChooser, the selectedColor property changes, and the JColorChooser generates a ChangeEvent to notify any registered ChangeListener objects.

Therefore, to complete the earlier ColorSample example, and have the foreground color of the label change when the user changes the color selection within the JColorChooser, you need to register a ChangeListener with the color chooser. This involves creating a ChangeListener and adding it to the ColorSelectionModel. Placing the following source code where the more source to come comment appears in the previous example is necessary for this example to work properly.

     ColorSelectionModel model = colorChooser.getSelectionModel();     ChangeListener changeListener = new ChangeListener() {       public void stateChanged(ChangeEvent changeEvent) {         Color newForegroundColor = colorChooser.getColor();         label.setForeground(newForegroundColor);       }     };     model.addChangeListener(changeListener); 

Once this source is added, the example is complete. Running the program brings the first screen shot, and selecting a new color alters the foreground of the label.

Although the previous example is sufficient, if you want to include a JColorChooser within your own window, more often than not you want the JColorChooser to appear in a separate popup window. This window might appear as the result of selecting a button on the screen, or possibly even selecting a menu item. To support this behavior, the JColorChooser includes the following factory method:

 public static Color showDialog(Component parentComponent,   String title, Color initialColor) 

When called, showDialog() creates a modal dialog box with the given parent component and title. Within the dialog box is a JColorChooser whose initial color is the one provided. As the second screen shot shows, along the bottom are three buttons: OK, Cancel, and Reset. When OK is pressed, the popup window disappears and the showDialog() method returns the currently selected color. When Cancel is pressed, null is returned instead of the selected color or the initial color. Selection of the Reset button causes the JColorChooser to change its selected color to the initial color provided at startup.

What normally happens with the showDialog() method is that the initial color argument is some color property of an object. The returned value of the method call then becomes the new setting for the same color property. This usage pattern is shown in the following lines of code, where the changing color property is the background for a button. As with JOptionPane, the null parent-component argument causes the popup window to be centered on the screen instead of over any particular component.

 Color initialBackground = button.getBackground(); Color background = JColorChooser.showDialog(   null, "Change Button Background", initialBackground); if (background != null) {   button.setBackground(background); } 

To place this code in the context of a complete example, the following source code offers a button that when selected displays a JColorChooser. The color selected within the chooser becomes the background color of the button after the OK button is selected.

 import java.awt.*; import java.awt.event.*; import javax.swing.*;  public class ColorSamplePopup {    public static void main(String args[]) {     Runnable runner = new Runnable() {       public void run() {         JFrame frame = new JFrame("JColorChooser Sample Popup");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          final JButton button =                         new JButton("Pick to Change Background");          ActionListener actionListener = new ActionListener() {           public void actionPerformed(ActionEvent actionEvent) {             Color initialBackground = button.getBackground();             Color background = JColorChooser.showDialog(               null, "Change Button Background", initialBackground);             if (background != null) {               button.setBackground(background);             }           }         };         button.addActionListener(actionListener);         frame.add(button, BorderLayout.CENTER);          frame.setSize(300, 100);         frame.setVisible(true);       }     };     EventQueue.invokeLater(runner);   } } 

There is much much more you can do with a JColorChooser, like showing a custom preview panel or creating your own color chooser panels. While the challenge asks you to create your own preview panel, if you don't want one shown, you must use a component with no size, like an empty container, as shown here.

   colorChooser.setPreviewPanel(new JPanel()); 

Making Sense of the Java Classes & Tools
 
Using Java DB in Desktop Applications

by John O'Conner

Sun Microsystems recently announced that it is distributing and supporting Java DB based on the 100 percent Java technology, open-source Apache Derby database. Derby was previously available under its earlier name, Cloudscape, from its former owners: Cloudscape, Informix, and IBM. IBM donated the Derby product source code to the Apache Foundation as an open-source project. Sun, IBM, other companies, and individuals have been actively involved in development of the relational database as part of the Apache Derby community. Sun distributes Java DB in many of its products, including the Sun Java Enterprise System and the Sun Java System Application Server. The NetBeans integrated development environment (IDE) 5.0 also supports Java DB.

Java DB is lightweight at two megabytes, and embeddable within desktop Java technology applications. Desktop applications can now access powerful database storage with triggers, stored procedures, and support for SQL, Java DataBase Connectivity (JDBC) software, and Java Platform, Enterprise Edition (Java EE, formerly referred to as J2EE), all embedded within the same Java virtual machine (JVM).*

This article describes how to download, install, integrate, and deploy Java DB within desktop Java technology applications. A demo application called Address Book demonstrates how to work with Java DB as an embedded database.

Read the article.

Java Bits
 
J2SE FAQ


This collection provides brief answers to a few common questions about the Java Platform, Standard Edition (Java SE).  It also links to more detailed information available from the java.sun.com web site.

Read the rest of this article.

What's New on Java Studio Creator
 
Using the File Upload Component


The File Upload component enables users of your web application to locate a file on their system and upload that file to the server. This component is useful for collecting text files, image files, and other data. The contents of the uploaded file are stored together with some information about the file, including the file name, size, and MIME type (such as text/plain or image/jpeg).

The server holds the uploaded file in memory unless it exceeds 4096 bytes, in which case the server holds the file contents in a temporary file. You can change this threshold by modifying the sizeThreshold parameter for the UploadFilter filter entry in the web application's web.xml file. For more information on modifying the web.xml file, see the last section in this tutorial, Doing More: Modifying the Maximum File Upload Size.

In cases where you want to retain the uploaded file, you have three choices:
  • Write the file to a location of your choosing, as shown in this tutorial.
  • Create an UploadedFile property in a managed bean and set it to the component's value before you exit the page (as in the button's action method).
  • Save the file to a database.
By default, the File Upload component can handle files up to one megabyte in size. You can change the maximum file size by modifying the maxSize parameter for the UploadFilter filter entry in the application's web.xml file, as described in the last section in this tutorial, Doing More: Modifying the Maximum File Upload Size.

Read the rest of this article.

Tutorials and Tips on NetBeans.org
 
NetBeans IDE 5.0 HTML Editor Tutorial


This tutorial demonstrates how to build an HTML editor, without any Java coding whatsoever. The HTML editor that you create is a rich-client application built "on top of the NetBeans Platform". What this means is that the core of the IDE, which is what the NetBeans Platform is, will be the base of your application. On top of the NetBeans Platform, you add the plug-in modules that you need and exclude the ones that the IDE needs but that your application doesn't. Here you see some of the IDE's plug-in modules, added to the NetBeans Platform, which is its base:

The IDE's plug-in modules, added to the NetBeans Platform

You will see for yourself how simple and easy it is to build, or to be more precise, to assemble, a full-featured application on top of the NetBeans Platform. At the end, you are shown how to make the final product easily downloadable and launchable using WebStart.

Read the rest of the tutorial.

 
 
Applet Deployment Guide for Microsoft Internet Explorer

by Stanley Ho

A recent update to Microsoft Internet Explorer 6 included a change that alters the way users interact with applets in the browser. Microsoft Internet Explorer 6 running on the following platforms are affected by this change:
  • Microsoft Windows XP Service Pack 2 (SP2)
  • Microsoft Windows Server 2003 Service Pack 1 (SP1)
  • Supported versions of Windows XP and Windows Server 2003
With this change, users can no longer directly interact with applets by default. Users are first required to manually activate the applet's user interface, before interacting with the applets. If the page has multiple applets, users have to activate each applet's user interface individually.

Impact on Applets

Interactive applets loaded directly from the web page in Internet Explorer are affected. However, if the applets are loaded from external script files, they can respond to user interaction immediately and are not affected by this change.

Activating the Applet for Interaction

When the applet is inactive, it does not respond to user's input. However, it performs operations that do not involve interaction. For example, when users open a web page which contains an applet, the applet loads and runs as usual. To activate the applet for interaction, users need to manually click on the applet, or use the Tab key to set focus on the applet and then press the Spacebar or the Enter key.

Workaround

To create web pages that load interactive applets that respond immediately to user input, developers can use JavaScript programming language to load the applets from external script files. Developers should not write script elements inline (for example, using the writeln function) with the main HTML page to load a control externally, because the loaded applet will behave as if it was loaded by the HTML document itself and will require activation. To ensure an applet is interactive when it is loaded, use one of the following techniques.

Read the rest of this article.

Sun's Technology Courses
 
Object-Oriented Analysis and Design Using UML (OO-226)


The Object-Oriented Analysis and Design Using UML course effectively combines instruction on the software development processes, object-oriented technologies, and the Unified Modeling Language (UML). This instructor-led course uses lecture, group discussion, and facilitator-led activities (such as analyzing stakeholder interviews) to present one practical, complete, object-oriented analysis and design (OOAD) roadmap from requirements gathering to system deployment.

Students are provided a pragmatic approach to object-oriented (OO) software development using a widely adapoted methodology (the Unified Process), the latest UML specification (version 1.4), and OO technologies, such as the Java programming language.

Learn more.

Free Developer Tools
 
Sun is offering the award-winning Sun Java Studio Enterprise and Sun Java Studio Creator IDEs at no cost to all developers worldwide who join Sun Developer Network (SDN).

Get your free tools.

For More Information
 
The terms "Java Virtual Machine" and "JVM" mean a Virtual Machine for the Java platform.


Downloading the Java Platform, Standard Edition (Java SE, formerly known as J2SE)
 
For most Java technology development, you need the class libraries, compiler, tools, and runtime environment provided with the Java SE development kit.


Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.
Comments? Send your feedback on the Java Technology Fundamentals Newsletter to: fundamentals_newsletter@sun.com

Find archived issues of the following Java technology developer newsletters or manage your current newsletter subscriptions: https://softwarereg.sun.com/registration/developer/en_US/subscriptions

Subscribe to the following newsletters for the latest information about technologies and products in other Java platforms:
  • Core Java Technologies Newsletter. Learn about new products, tools, resources, and events of interest to developers working with core Java technologies.
  • Mobility Developer Newsletter. Learn about the latest releases, tools, and resources for developers working on wireless and Java Card technologies and applications.
  • Enterprise Java Technologies Newsletter. Learn about the latest in enterprise Java technology: releases, products, tools, resources, events, news, and views.
  • Core Java Technologies Tech Tips (formerly JDC Tech Tips). Get expert tips, sample code solutions, and techniques for developing in the Java Platform, Standard Edition (Java SE)
You can subscribe to these and other JDC publications on the JDC Newsletters and Publications page

PRIVACY STATEMENT

Sun respects your online time and privacy. You have received this based on your email preferences. If you would prefer not to receive this information, please follow the steps at the bottom of this message to unsubscribe.

IMPORTANT: Please read our Terms of Use, Privacy, and Licensing policies:
http://www.sun.com/share/text/termsofuse.html
http://www.sun.com/privacy/
http://developer.java.sun.com/berkeley_license.html

© 2006 Sun Microsystems, Inc. All Rights Reserved. For information on Sun's trademarks see: http://sun.com/suntrademarks
Java, J2EE, J2SE, J2ME, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.

To update your Sun subscription preferences or unsubscribe to Sun news services, click here or use this link https://softwarereg.sun.com/registration/developer/en_US/subscriptions



FEEDBACK

Comments? Send your feedback on the Java Technology Fundamentals Newsletter to dana.nourie@sun.com

Sun Microsystems, Inc. 10 Network Circle, MPK10-209 Menlo Park, CA 94025 US



Please unsubscribe me from this newsletter.


 
Comments: Post a Comment



<< Home
News, Articles, events from all over the world

My Photo
Name:
Location: India

Born on shraavana shudha chauthi of dundubhi naama samvaswara, Im kiran alias kini alias kiri bought up by loving parents. Being from agricultural family I have learnt plowing, carting but never learnt climbing trees. Now away from home I have lost touch with the agricultural skills.

ARCHIVES
January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 /


Powered by Blogger