Creating of Rich Client Applications using Net Beans
Creating of Rich Client Applications using Net. Beans 6 and Java Swing Miroslav Nachev
Contents n n n Swing. X Simple Database Application Another simple Database Application with Master. Table and Detail. Table Rich Client Application example Swing Application Framework Q&A
Swing. X n Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. Swing. X Demo
Swing. X highlights include: n n n n Sorting, filtering, highlighting for tables, trees, and lists Date picker component Find/search Auto-completion Login/authentication framework Tree. Table component Collapsible panel component Tip-of-the-Day component
Swing. X links n Links: http: //www. swinglabs. org/ n https: //swingx. dev. java. net/ n https: //swinglabs-demos. dev. java. net/ n https: //swinghelper. dev. java. net/ n http: //wiki. java. net/bin/view/Javadesktop/Swi ng. Labs. Swing. X n
Simple Database Application n n Creating a Database “car_db” Creating the Application “Cars. App” Transaction type: JTA in a Java. EE and RESOURCE_LOCAL in a Java. SE Transaction model: persists all and commit to save or rollback to cancel. properties files containing the labels in the user interface
Features that are already built into the application n Car. java entity bean n n Bean to Table relation using annotations Property Change notification Persistence unit: META-INF/persistence. xml, defines a connection between the database and the entity class. Using beans binding (JSR 295) to connect the properties of the entity class with the properties of the JTable component. The entity. Manager, query, and list objects, which are defined in the Cars. View class
Adding More Controls n n “Tire Size” slider “Modernness” slider “Spoiler” checkbox “Roof” checkbox
Binding Controls to Values in the Table n n n In the form, right-click the first slider and choose Bind > value. In the Binding Source drop-down list of the Binding dialog box, select master. Table. In the Binding Expression drop-down list, selected. Element > tiresize. Click the Advanced tab. Select the Unreadable Source Value checkbox. Click the ellipsis (. . . )button that is next to the Unreadable Source Value checkbox.
Binding Controls to Values in the Table n In the Incomplete Path Value dialog box, select Custom Code from the drop-down list. Then type the integer 0. n Right-click the checkbox and choose Customize Code. In white line under the binding. Group. add. Binding(binding) line, type: binding. set. Source. Unreadable. Value(false); n Run application and verify into Databse n n
Setting up a Custom Component n n n Adding Car Preview package Drag the Car. Preview. java class (Java. Beans component) to the form Bind all the binding properties of the Car. Preview component to the corresponding selected. Element attributes of the master. Table
Another simple Database Application with Master. Table and Detail. Table n n n Creating a new Database Connection to Swing_Demo Creating the Application “Master. Detail. Demo” Adding annotation @Generated. Value to Entity beans
Changes in detail. Table n n n Switch to Binding category in Properties window Select elements property Invoke property customizer (Press. . . button) Switch to Advanced tab. Check 'Unreadable Source Value' (<none> should be selected in combo next to this checka 1 box).
Starting of the application with Open. JPA agent Select root node of your project in Projects window. n Invoke Properties action from contextual menu of this node. n Select Run node (in the tree on the left). n Enter: -javaagent: <PATH_TO_OPENJPA_JAR>/openjpa 1. 0. 1. jar into VM Options field. n
Rich Client Application example n n n Creating the Application “Rich. Client. App” Creating a Swing Application Separating Business Logic Interfaces from EJB Implementation (Module)
Swing Application Framework Architecture. Two classes help you manage your application (one-to-one relationship): n n n Application. Context services: n n Localizable resource management Task services and monitoring Event-action management Session-state storage
From where to start All Swing Application Framework applications must subclass either the Application class or its Single. Frame. Application subclass. The Single. Frame. Application adds a default main GUI frame, retrieves and injects default resources, and uses the Application. Context to save and restore simple session state. Session state includes UI component location, size, and configuration.
Application Life Cycle n n n launch -- You must call this framework method. initialize -- The framework will invoke this optional overridden method. startup -- The framework will invoke this overridden method. ready -- The framework will invoke this optional overridden method. exit -- You must call this framework method. shutdown -- The framework will invoke this optional overridden method.
Example subclasses the Application class public class Basic. Framework. App extends Application { private JFrame main. Frame; private JLabel label; protected void startup() { main. Frame = new JFrame("Basic. Framework. App"); main. Frame. set. Default. Close. Operation(JFrame. DO_NOTHING_ON_CLOSE); main. Frame. add. Window. Listener(new Window. Adapter() { public void window. Closing(Window. Event e) { mainframe. set. Visible(false); exit(); } }); label = new JLabel("Hello, world!"); main. Frame. add(label); main. Frame. pack(); main. Frame. set. Visible(true); } public static void main(String[] args) { Application. launch(Basic. Framework. App. class, args); } }
Example subclasses the Single. Frame. Application class public class Basic. Single. Frame. App extends Single. Frame. Application { JLabel label; protected void startup() { get. Main. Frame(). set. Title("Basic. Single. Frame. App"); label = new JLabel("Hello, world!"); label. set. Font(new Font("Sans. Serif", Font. PLAIN, 22)); show(label); } public static void main(String[] args) { Application. launch(Basic. Single. Frame. App. class, args); } }
Exit. Listener interface n The Exit. Listener interface has two methods: public boolean can. Exit(Event. Object e) n public void will. Exit(Event. Object e) n
- Slides: 21