Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev.

Similar presentations


Presentation on theme: "Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev."— Presentation transcript:

1 Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev

2 Contents SwingX SwingX Simple Database Application Simple Database Application Another simple Database Application with MasterTable and DetailTable Another simple Database Application with MasterTable and DetailTable Rich Client Application example Rich Client Application example Swing Application Framework Swing Application Framework Q & A Q & A

3 SwingX Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. SwingX Demo SwingX Demo

4 SwingX highlights include: Sorting, filtering, highlighting for tables, trees, and lists Sorting, filtering, highlighting for tables, trees, and lists Date picker component Date picker component Find/search Find/search Auto-completion Auto-completion Login/authentication framework Login/authentication framework TreeTable component TreeTable component Collapsible panel component Collapsible panel component Tip-of-the-Day component Tip-of-the-Day component

5 SwingX links Links: Links: http://www.swinglabs.org/ http://www.swinglabs.org/ http://www.swinglabs.org/ https://swingx.dev.java.net/ https://swingx.dev.java.net/ https://swingx.dev.java.net/ https://swinglabs-demos.dev.java.net/ https://swinglabs-demos.dev.java.net/ https://swinglabs-demos.dev.java.net/ https://swinghelper.dev.java.net/ https://swinghelper.dev.java.net/ https://swinghelper.dev.java.net/ http://wiki.java.net/bin/view/Javadesktop/Swi ngLabsSwingX http://wiki.java.net/bin/view/Javadesktop/Swi ngLabsSwingX http://wiki.java.net/bin/view/Javadesktop/Swi ngLabsSwingX http://wiki.java.net/bin/view/Javadesktop/Swi ngLabsSwingX

6 Simple Database Application Creating a Database “car_db” Creating a Database “car_db” Creating the Application “CarsApp” Creating the Application “CarsApp” Transaction type: JTA in a JavaEE and RESOURCE_LOCAL in a JavaSE Transaction type: JTA in a JavaEE and RESOURCE_LOCAL in a JavaSE Transaction model: persists all and commit to save or rollback to cancel Transaction model: persists all and commit to save or rollback to cancel.properties files containing the labels in the user interface.properties files containing the labels in the user interface

7 Features that are already built into the application Car.java entity bean Car.java entity bean Bean to Table relation using annotations Bean to Table relation using annotations Property Change notification Property Change notification Persistence unit: META-INF/persistence.xml, defines a connection between the database and the entity class. 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. Using beans binding (JSR 295) to connect the properties of the entity class with the properties of the JTable component. The entityManager, query, and list objects, which are defined in the CarsView class The entityManager, query, and list objects, which are defined in the CarsView class

8 Adding More Controls “Tire Size” slider “Tire Size” slider “Modernness” slider “Modernness” slider “Spoiler” checkbox “Spoiler” checkbox “Roof” checkbox “Roof” checkbox

9 Binding Controls to Values in the Table In the form, right-click the first slider and choose Bind > value. 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 masterTable. In the Binding Source drop-down list of the Binding dialog box, select masterTable. In the Binding Expression drop-down list, select selectedElement > tiresize. In the Binding Expression drop-down list, select selectedElement > tiresize. Click the Advanced tab. Click the Advanced tab. Select the Unreadable Source Value checkbox. Select the Unreadable Source Value checkbox. Click the ellipsis (...)button that is next to the Unreadable Source Value checkbox. Click the ellipsis (...)button that is next to the Unreadable Source Value checkbox.

10 Binding Controls to Values in the Table In the Incomplete Path Value dialog box, select Custom Code from the drop-down list. Then type the integer 0. In the Incomplete Path Value dialog box, select Custom Code from the drop-down list. Then type the integer 0. Right-click the checkbox and choose Customize Code. Right-click the checkbox and choose Customize Code. In white line under the bindingGroup.addBinding(binding) line, type: In white line under the bindingGroup.addBinding(binding) line, type: binding.setSourceUnreadableValue(false); binding.setSourceUnreadableValue(false); Run application and verify into Databse Run application and verify into Databse

11 Setting up a Custom Component Adding Car Preview package Adding Car Preview package Drag the CarPreview.java class (JavaBeans component) to the form Drag the CarPreview.java class (JavaBeans component) to the form Bind all the binding properties of the CarPreview component to the corresponding selectedElement attributes of the masterTable Bind all the binding properties of the CarPreview component to the corresponding selectedElement attributes of the masterTable

12 Another simple Database Application with MasterTable and DetailTable Creating a new Database Connection to Swing_Demo Creating a new Database Connection to Swing_Demo Creating the Application “MasterDetailDemo” Creating the Application “MasterDetailDemo” Adding annotation @GeneratedValue to Entity beans Adding annotation @GeneratedValue to Entity beans

13 Changes in detailTable Switch to Binding category in Properties window Switch to Binding category in Properties window Select elements property Select elements property Invoke property customizer (Press... button) Invoke property customizer (Press... button) Switch to Advanced tab. Switch to Advanced tab. Check 'Unreadable Source Value' ( should be selected in combo next to this check- a1box). Check 'Unreadable Source Value' ( should be selected in combo next to this check- a1box).

14 Starting of the application with OpenJPA agent Select root node of your project in Projects window. Select root node of your project in Projects window. Invoke Properties action from contextual menu of this node. Invoke Properties action from contextual menu of this node. Select Run node (in the tree on the left). Select Run node (in the tree on the left). Enter: Enter: -javaagent: /openjpa- 1.0.1.jar into VM Options field.

15 Rich Client Application example Creating the Application “RichClientApp” Creating the Application “RichClientApp” Creating a Swing Application Creating a Swing Application Separating Business Logic Interfaces from EJB Implementation (Module) Separating Business Logic Interfaces from EJB Implementation (Module)

16 Swing Application Framework Framework Architecture. Two classes help you manage your application (one-to-one relationship): Framework Architecture. Two classes help you manage your application (one-to-one relationship): ApplicationContext ApplicationContext Application Application ApplicationContext services: ApplicationContext services: Localizable resource management Localizable resource management Task services and monitoring Task services and monitoring Event-action management Event-action management Session-state storage Session-state storage

17 From where to start All Swing Application Framework applications must subclass either the Application class or its SingleFrameApplication subclass. The SingleFrameApplication adds a default main GUI frame, retrieves and injects default resources, and uses the ApplicationContext to save and restore simple session state. Session state includes UI component location, size, and configuration.

18 Application Life Cycle launch -- You must call this framework method. launch -- You must call this framework method. initialize -- The framework will invoke this optional overridden method. initialize -- The framework will invoke this optional overridden method. startup -- The framework will invoke this overridden method. startup -- The framework will invoke this overridden method. ready -- The framework will invoke this optional overridden method. ready -- The framework will invoke this optional overridden method. exit -- You must call this framework method. exit -- You must call this framework method. shutdown -- The framework will invoke this optional overridden method. shutdown -- The framework will invoke this optional overridden method.

19 Example subclasses the Application class public class BasicFrameworkApp extends Application { private JFrame mainFrame; private JLabel label; protected void startup() { mainFrame = new JFrame("BasicFrameworkApp"); mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { mainframe.setVisible(false); exit();}}); label = new JLabel("Hello, world!"); mainFrame.add(label);mainFrame.pack();mainFrame.setVisible(true);} public static void main(String[] args) { Application.launch(BasicFrameworkApp.class, args); } }

20 Example subclasses the SingleFrameApplication class public class BasicSingleFrameApp extends SingleFrameApplication { JLabel label; protected void startup() { getMainFrame().setTitle("BasicSingleFrameApp"); label = new JLabel("Hello, world!"); label.setFont(new Font("SansSerif", Font.PLAIN, 22)); show(label);} public static void main(String[] args) { Application.launch(BasicSingleFrameApp.class, args); }}

21 ExitListener interface The ExitListener interface has two methods: The ExitListener interface has two methods: public boolean canExit(EventObject e) public boolean canExit(EventObject e) public void willExit(EventObject e) public void willExit(EventObject e)


Download ppt "Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev."

Similar presentations


Ads by Google