Java And Swing PDF Print E-mail
User Rating: / 0
PoorBest 
Tuesday, 27 May 2008

After being handed over to "secondary" Sun emphasized that the server side with J2EE, Java now back little by little on the front side of the stage score. Indeed, the next update of Java 6 should already make a lot of things on the subject with the "Consumer JRE."

And Java 7 will continue in the same direction. The versions are already developing a solution to the mixture components AWT and Swing. It also speaks of a Java Media Components that would bring the management of playing videos in standard (without the extension JMF).

But we must remember especially the addition of two new APIs to facilitate application development Swing: Swing Application Framework and Beans Binding ...
[:]
JSR 296: Swing Application Framework

Swing has to be a beautiful sophisticated graphics API, it is nonetheless enough "gross stripping", meaning that even if she has what it takes to develop a graphical user interface, we must manage virtually all the hand!

The goal of the JSR 296 is therefore to fill this big hole in proposing a common infrastructure to most desktop applications:
Management lifecycle of the application via a class Application.

Support for the management and loading the resources of the application (chains, images, colors, etc.)..
Improved management of shares and their associations with components of the interface.
Management of the persistence of the application, safeguarding its characteristics (size, position, etc.). Of a performance to another.
Management salaries in the background so as not overloaded EDT.
and so on.

I do not rentrerais more detail but I will simply transcribe here a typical example of "Hello World":
   public class SingleFrameExample2 extends SingleFrameApplication (
     public void startup (String [] args) (
       JLabel label = new JLabel ();
       label.setName ( "label");
       show (label);
     )
 
     public static void main (String [] args) (
       launch (SingleFrameExample2.class, args);
     )
   )

The method of entry standard Java applications (main ()) is used here to start our application via the static method launch (). The latter will among others to create and initialize our application and call its method startup () in the EDT. The latter is therefore satisfied to implement the code of the founding of the interface, and uses the show () method for creating automatically JFrame which contains our application.

But where it gets more interesting is that the framework can combine data automatically a file properties for different components of our interface via their names (and that's all the interest of label.setName ( " label ")). Thus, linking this with the file properties:
label.opaque = true
label.background = 0, 0, 0
label.foreground = 255, 255, 255
label.text = Hello World
label.font = Lucida-PLAIN-48
label.icon = earth.png

We get this:

Swing Application Framework will also offer many other features facilitating the design GUI, which I unfortunately can not detail here ...
But if the topic interests you I strongly urge you to consult on the draft appframework java.net, which allows among others download the developing (compatible Java 6) or consult an introduction to the framework quite clear and interesting.
JSR 295: Beans Binding

 

The JSR 295 will synchronize beans between them. At present it is necessary to use PropertyChangeListeners to be notified of changes in a property in order to pass on the other. Indeed, each component Swing manages PropertyEvents who can report any changes in ownership component. If it can be very useful in practice it quickly becomes burdensome and rather tedious. The Beans Binding facilitate all of this!

Take a simple example or a checkbox (JCheckBox) would activate or not an input area (JTextArea). Beans Binding offer everything needed to link these two properties together:
   JCheckBox checkBox = ...
   JTextArea textArea = ...
    
   Bindings.createAutoBinding (UpdateStrategy.READ_WRITE,
       textArea, BeanProperty.create ( "enabled")
       checkBox, BeanProperty.create ( "selected"))
     . Bind ();

Henceforth, the property "enabled" the text box will be linked to property "selected" by the check box, and an amendment of any of these properties will be immediately passed on to another while updating the display components, using implicitly PropertyChangeListeners. There's nothing more to do!

It is also possible to use converters to link seemingly incompatible properties (for example linking the value of a text field to a property type Date), and make a prior validation of data. Without forgetting the management of property more as a specific cell in a JTable, or the possibility of linking a property to an external resource (web service or database).

The Beans Binding also have their project on java.net that allows you to get a glimpse of the developing ...

Notices
These two new APIs will significantly contribute to simplifying the development of graphics applications Swing, while offering a standardized framework which will use them directly via EDI Java. Indeed NetBeans 6.0 has already started to integrate the management of these JSRs in his graphic design tool ...

 
< Prev   Next >
School Joomla Templates and Joomla Tutorials