This section explains the method of creating user interface processing. This is relevant for forms, applets, and the visible Beans of JavaBeans.
This section explains the processing of an application that displays a frame, as an example of an application with a user interface.
The processing includes the following:
Main program: Initialization of the application and display of a form
Initialization processing: Initialization processing of the form
Event processing: Processing of events generated by actions such as user operations
Example of main program that displays a frame
public class MyJavaApp { //Constructor public MyJavaApp() { } //Method that displays a frame public void run() { //Create a frame instance. Frame1 form = new Frame1(); //Use setVisible method of the frame instance and enable display. form.setVisible(true); } //Main processing public static void main(String[] args) { //Create a MyJavaApp class instance. MyJavaApp object = new MyJavaApp(); //Invoke a run method of the MyJavaApp class instance. object.run(); } }
Forms are made up of frames, dialogs, and panels.
This section explains the description of the processing, using frames as an example.
Frame operation
This section explains frame operation as an example of operation.
Sharing information
If data is to be shared between the main program and the Java Form or among Java Forms, either define the data in the main program and reference that data in each form, or add a constructor and pass the data that is to be shared as a parameter.
Frame display method
An example of a frame display method is shown below.
If a frame called Frame1 is to be invoked from an application or existing frame Frame1 form = new Frame1(); //Create a frame instance. form.init(); //Initialize the frame. form.setVisible(true); //Display the frame.
Frame close method
To close a frame, describe "this.dispose();".
This section explains how to operate a Bean.
A Bean that has been pasted into a Java Form will be generated as a class field of a Java Form class. The class field will have the name specified in the "Bean name" property when the Java Form was defined.
Bean operation is performed by setting and referencing Bean properties and invoking Bean methods.
Referencing and setting properties
An example of referencing and setting properties is shown below.
A focus_focusGained event to be generated when the text field Bean "textField1" gains focus is used to modify the background color (background) property to blue. In addition, a focus_focusLost event to be generated when focus is lost is used to return the background color (background) property to white.
[Processing of TextField1] public void textField1_focus_focusGained(FocusEvent e) { if (!defaultEventProc(e)) { textField1.setBackground(java.awt.Color.blue); } } public void textField1_focus_focusLost(FocusEvent e) { if (!defaultEventProc(e)) { textField1.setBackground(java.awt.Color.white); } }
Invoking a method
An example of invoking a method is shown below.
When the push button "button1" is pressed, the characters that have been entered in the "textField1" text field are added to the "list1" list box.
[Processing of button1] public void button1_action_actionPerformed(ActionEvent e) { if (!defaultEventProc(e)) { list1.addItem(textField1.getText()); } }
There are three methods of adding event processing:
Using the Java editor to describe event processing directly
Use the Java editor to describe a direct method for each event.
Using the Bean Relationships Creation Wizard to generate event processing
When this wizard is used, processing can be generated interactively rather than via programming. Refer to "7.3.6.4 Creating Bean Relationships" for details.
Using the Bean List view to insert event processing
The Bean List view displays a list of the Java Forms and Beans that have been edited by the Java Form Designer and has a function to insert methods and events. The Bean List view has the following functions:
Displaying a list of the Beans that have been edited by the Java Form Designer
Allows the Beans that have been edited in a Java Form to be displayed in tree format
Displaying a list of the properties, methods, and events of each Bean
Expands the properties, methods, and events to allow these details to be listed for each Bean
Inserting methods in the source
Allows the [Method Insert] dialog box to be used to easily insert methods in the source
Inserting events in the source
Allows events to be easily inserted in the source