Java Reference
In-Depth Information
Listing 10.3
A main() method that invokes the GUI
...
public static void main(String[] args) {
MyForm form = new MyForm();
JFrame frame = new JFrame("My Form");
frame.setContentPane(form.mainPanel);
frame.pack();
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.show();
}
...
Within your form class, you can access any of the components you've bound to
fields within the class. You don't need to do any special initialization; by selecting
them for binding, IDEA initializes them at the beginning of your class's construc-
tor. You're free to hook up action listeners to your buttons, load initial data into
JT ables, or whatever other setup you require.
10.6 Adding functionality to the ACME GUI
Now that we've talked about the fundamentals of adding functionality, let's make
the ACME GUI do what it's intended to do: perform a currency conversion. You've
already laid out the GUI , so it's a matter of specifying the form class and adding
functionality to it to bridge the gap between the currency conversion library and
the interface.
10.6.1
Binding the ACME GUI to a form class
First, you need to bind the form to a new class. Select the root node of the tree—
the one that represents the form as a whole—in the component tree view. Edit its
bind to class property, and type in the value com.acme.conversion.currency.
client.ACMEGUI . When you press Enter to accept this value, you'll notice that the
form node on the component tree view is visually marked as having an error (by
default, IDEA uses the wavy red underline that you've probably seen in open Java
files). Click the form node of the component tree view once more, and you'll see
the error: the class doesn't exist. You'll also see the light bulb icon that suggests an
intention action. Open the light bulb, and select the Create class intention action
option. The new form class is created for you.
 
 
 
 
Search WWH ::




Custom Search