You can quickly create a project in which to organize your
application files, a runnable application class file,
and a frame class in which you can lay out UI controls.
Then work in JDeveloper's IDE to develop, compile, run,
debug, and optimize your application.
Create a New Application and Project: Use
the Create Application wizard to create a new application
and project for your Java Swing application.
Create a Java Application: Use
the Create Java Application dialog to create the skeleton
files for your Java Swing
application.
Develop the UI: Use the Java visual editor
to easily assemble the elements of a user interface (UI)
for your Java application using Swing components.
Finish Coding: To finish development, use the Java source
editor, which provides functionality such as Java Code Insight and
import statement assistance as you edit your source files.
Compile: Build your project utilizing the speed and
advanced functionality of the Java Compiler (Javac).
Debug: Use the UI debugger to control
the execution of your program while you debug it.
Create a New Application and Project
Creating a New Application and Project
The application control file is the
highest level in the organizational structure. It stores
information about the objects you are working with, while
you are creating your application. It keeps track of your
projects and the environment settings while you are developing
your Java program. [tell me more...]
Open the Create Application wizard [File > New > General > Applications > Application] .
Enter the application name MySwingApplication to follow along
with the example.
Application Templates
Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of technologies already specified. The new application created from the template appears in the Application Navigator already partitioned into tiered projects, with the associated technology scopes set in each project. [tell me more...]
Select Java Desktop Application from
the Application Template list, and click Finish.
In the IDE
When you create your application based on the Java Desktop
Application template, JDeveloper adds a project file named Client.jpr,
so the Application Navigator should look like this: [tell me more...]
Create a Java Application
Creating a Java Application
You can quickly create a runnable application class file
and, optionally, a frame class that you can lay out with
UI controls. [tell me more...]
In the Application Navigator, select the project you just created and
open the Create Java Application dialog [File > New > Client Tier > Swing/AWT > Java Application] .
Java
Application Files
When you use the Create Java Application dialog and
the subsequent Create Frame dialog, JDeveloper adds a skeleton
application file and a frame file to your project, which
by default are named Application1.java and Frame1.java. [tell me more...]
Accept the default name and package for the class.
Under Optional Attributes, accept the default values to create a new frame and click OK.
In the Create Frame dialog, accept the default name
and package for the class.
Under Optional Attributes, enter My Java Swing Application as the title for the frame. Then select Menu Bar, Status Bar, and About Box to create those items for this first frame. Then click OK.
In the IDE
When you create your Java application, the Application Navigator should look like this, if all nodes are expanded: [tell me more...]
Edit with the Java Visual Editor
Editing with the Java Visual Editor
Using JDeveloper's Java visual editor, you can quickly
and easily assemble the elements of a user interface (UI)
for a Java application using Swing components. You construct
the UI with JavaBeans (such as buttons, text areas, lists,
dialogs, and menus) selected from the Component Palette.
Then, you set the values of the component properties and
attach event-handler code to the component events. [tell me more...]
On the Swing page of the Component Palette, Components panel,
select the JButton component
and then drag and drop it in the
frame in the visual editor.
Resize the component by clicking to display its grab bars and then dragging the bars.
Modify the position of the component by clicking and dragging it in the frame.
In the Property Inspector expand the Visual section,
then change the default text that displays on the button by
entering
Click here in the text field.
Editing with the Property Inspector
The Property Inspector lets you inspect and set component
properties and attach methods to component events. Changes
made in the Property Inspector are reflected in the Java
visual editor and source code. The Property Inspector displays
the properties of the component selections you make in
the Java visual editor. The components are organized by
categories, and can be easily located with the Find field
on the toolbar. [tell me more...]
With the button still selected, expand the Events section in the Property Inspector, then click the
actionPerformed (...) browse
button to open the Edit Property dialog. Click OK to
accept jButton1_actionPerformed as
the name for a generated method stub to be called from
the event handler.
Click Save
All to save your work.
In the IDE
When you insert the actionPerformed event, a method is generated and the source editor automatically switches to source view so that you can edit it. [tell me more...]
Edit with the Java Source Editor
Editing with the Java Source Editor
Features available to you in the source editor include: [tell me more...]
In the source editor, add sample code to the JDeveloper-generated
code, to add an action-performed event for the button. Use sample code
To (optionally) add your own code, start typing to activate Java Code Insight.
Using Java Source Editor Features
The insert or replace mode for the editor is controlled by the Insert key on the keyboard. The default is insert mode. Press Insert to toggle between insert and replace mode. [tell me more...]
To (optionally) add an import statement when you reference a class, select the name of the statement that appears below the ragged line.
To (optionally) see Code Assist's suggested fixes for specific problems in your code, click the Code Assist icon in the left margin.
In the IDE
If you added the code sample, the code at the bottom of the source editor should look like this: [tell me more...]
Compile and Run a Java Application
Compiling and Running a Java Application
You can compile several nodes in an application in any
combination: the entire application, an entire project,
or specific Java files. [tell me more...]
In the Application Navigator, right-click the project
and choose Make Client.jpr.
Choosing Between Make and Rebuild
You can compile by choosing either the Make or Rebuild command
from the Build or context
menu, or the toolbar. [tell me more...]
Once the project is compiled, in the Application Navigator, right-click the project and choose Run.
In the Choose Default Run Target dialog, browse and
select Application1.java,
which contains a main method, as the default run target.
Then click OK.
In the IDE
The Choose Default Run Target dialog displays when you
run a project for which no default run target is specified
in the Run/Debug/Profile settings of the Project Properties
dialog. [tell me more...]
Create a Java Class
Creating a Java Class
New classes can be created and added to your project after you build the initial set of project files. [tell me more...]
In the Application Navigator, select the Client project and
open the Create Java Class dialog [File > New > General > Java Class] .
Enter Class1 as the class name if you are using the sample code. Accept the package name.
If working with the sample code, enter javax.swing.JDialog in the Extends field, by clicking Browse and using the Class Browser.
Under Optional Attributes,
deselect Constructors from Superclass,
and confirm that Main
Method is not selected.
Then click OK.
In the editor window, select the Frame1.java tab
at the top, and then the Source tab
at the bottom, to view the Frame1.java file
in the source editor. Then add code to include this new
Java class file in your application. Use sample code
When your changes are complete, in the Application Navigator,
right-click the Client project
and choose Run.
In the IDE
When you create your Java class, the Application Navigator should look like this: [tell me more...]
Debug a Java Swing Application
Debugging a Java Swing Application
In addition to JDeveloper's standard Java and PL/SQL debugger
facilities, JDeveloper also provides support for debugging
graphical user interfaces (GUIs) specifically for AWT and
Swing-based client applications and applets. [tell me more...]
Choose Run UI
Debug Client.jpr to
start the project's default target and run the application.
Choose ViewJavaUI Debugger Tree, and click the
Snapshot icon
in the UI Tree window toolbar.
UI Debugger Windows
You can use the UI Debugger features which are exposed in JDeveloper via three dockable windows:
the UI Tree, the UI Outline, and the Events windows. The Events window appears the first time you track events.
You can toggle all three windows by choosing
ViewJavaUI Debugger Outline, Tree
or Events. [tell me more...]
Right-click the client.Frame1(0) component
in the UI Tree window and choose Trace
Events from
the context menu to open the Trace Events dialog.
Select java.awt.event.MouseListener from
the list and click OK.
Bring the application to the front, then move the
mouse into the Frame and note the generated events in
the Events window.
End the debugging session at any time by clicking Terminate.
In the IDE
When you start the UI debugger, the Log window opens and
displays the debugging trace. [tell me more...]