Title: Creating of Rich Client Applications using NetBeans 6 and Java Swing
1Creating of Rich Client Applications using
NetBeans 6 and Java Swing
2Contents
- SwingX
- Simple Database Application
- Another simple Database Application with
MasterTable and DetailTable - Rich Client Application example
- Swing Application Framework
- Q A
3SwingX
- Contains extensions to the Swing GUI toolkit,
including new and enhanced components that
provide functionality commonly required by rich
client applications. - SwingX Demo
4SwingX 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
5SwingX 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/SwingLab
sSwingX
6Simple 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
7Features 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
8Adding More Controls
- Tire Size slider
- Modernness slider
- Spoiler checkbox
- Roof checkbox
9Binding Controls to Values in the Table
- In the form, right-click the first slider and
choose Bind gt value. - In the Binding Source drop-down list of the
Binding dialog box, select masterTable. - In the Binding Expression drop-down list, select
selectedElement gt tiresize. - Click the Advanced tab.
- Select the Unreadable Source Value checkbox.
- Click the ellipsis (...)button that is next to
the Unreadable Source Value checkbox.
10Binding 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(bi
nding) line, type - binding.setSourceUnreadableValue(false)
- Run application and verify into Databse
11Setting 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
12Another simple Database Application with
MasterTable and DetailTable
- Creating a new Database Connection to Swing_Demo
- Creating the Application MasterDetailDemo
- Adding annotation _at_GeneratedValue to Entity beans
13Changes 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' (ltnonegt should be
selected in combo next to this check-a1box).
14Starting 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
- -javaagentltPATH_TO_OPENJPA_JARgt/openjpa-1.0.1.jar
into VM Options field.
15Rich Client Application example
- Creating the Application RichClientApp
- Creating a Swing Application
- Separating Business Logic Interfaces from EJB
Implementation (Module)
16Swing 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
17From 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.
18Application 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.
19Example 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_NOTH
ING_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) -
-
20Example 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) -
21ExitListener interface
- The ExitListener interface has two methods
- public boolean canExit(EventObject e)
- public void willExit(EventObject e)