1 / 21

Creating of Rich Client Applications using NetBeans 6 and Java Swing

Creating of Rich Client Applications using NetBeans 6 and Java Swing. Miroslav Nachev. Contents. SwingX Simple Database Application Another simple Database Application with MasterTable and DetailTable Rich Client Application example Swing Application Framework Q & A. SwingX.

yakov
Download Presentation

Creating of Rich Client Applications using NetBeans 6 and Java Swing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Contents • SwingX • Simple Database Application • Another simple Database Application with MasterTable and DetailTable • Rich Client Application example • Swing Application Framework • 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

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

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

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

  7. Features that are already built into the application • Car.java entity bean • 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 entityManager, query, and list objects, which are defined in the CarsView class

  8. Adding More Controls • “Tire Size” slider • “Modernness” slider • “Spoiler” 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 Binding Source drop-down list of the Binding dialog box, select masterTable. • In the Binding Expression drop-down list, select selectedElement > tiresize. • Click the Advanced tab. • Select 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. • Right-click the checkbox and choose Customize Code. • In white line under the bindingGroup.addBinding(binding) line, type: • binding.setSourceUnreadableValue(false); • Run application and verify into Databse

  11. Setting up a Custom Component • Adding Car Preview package • 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

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

  13. Changes in detailTable • 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 check-a1box).

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

  15. Rich Client Application example • Creating the Application “RichClientApp” • Creating a Swing Application • 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): • ApplicationContext • Application • ApplicationContext services: • Localizable resource management • Task services and monitoring • Event-action management • 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. • 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.

  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: • public boolean canExit(EventObject e) • public void willExit(EventObject e)

More Related