Java Reference
In-Depth Information
This fourth statement adds the empNameLbl Label to the Frame. Pretty simple. Then you need:
empFrame.setVisible( true );
This last statement sets the empFrame property visible to true. The default value is false , meaning the frame will
not appear on the screen. Try to remember that to see the frame you must change this property to true .
Notice that the Frame class has many setters (setBounds, setLayout, setVisible, etc.) to control the frame
properties. In addition, there are useful methods, such as add, to build the frame with other components. Earlier
we mentioned that the JRE contains all sorts of useful classes. Certainly all of these GUI classes can be included in
that category.
Some beginning programmers are concerned that they really don't know how the Frame class works and that
therefore they don't understand Java. The beauty and power of Java (and all object-oriented languages) is that
programmers use predefined components (classes) and assemble them into unique applications. Because the
programmer uses common, well-tested components, applications can be assembled quickly, will be more reliable,
and are easier to change in the future. For instance, a mason doesn't know the chemical composition of a cinderblock
or how cinderblocks are manufactured. He does know their properties—how much they weigh, their dimensions,
how much weight they can bear. In addition, the mason can change some properties. For instance, cinderblocks can
be cut down in size. The mason uses the cinderblocks (possibly changing some of their dimensions) to build a house
according to the specifications of the customer.
You are doing the same thing with the Java classes. You learn the properties of the Label and Frame classes
and then change the properties of individual objects to create an application that fits the customer's needs and
specifications. Therefore, you really don't need to know how the Frame class works. Simply use the class.
Another example would be driving. Do you really need to know how the brake system works? All you need to
know are the properties of the brake pedal. In other words, all you need to know is where the brake pedal is and that
when you step on the brake pedal very quickly, you will stop very quickly.
Tutorial: Creating a GUI with RAD
You are going to create a new project and package, and then copy the Employee application into it. You will then
modify the Employee application so that a frame and label are used to display the employee name.
Let's begin:
1.
Start RAD.
2.
If needed, switch to the Java perspective.
3.
Create a new Java project called Tutorials and within src, a package named c3.
4.
In the Navigation tree, expand MyFirstProject, src, and myFirstPackage.
5.
Click on Employee.java to select it, then hold the Ctrl key and click on EmployeeApp.java
to select it also.
6.
Click Edit , then Copy .
7.
Click on the c3 package in Tutorials to select it.
8.
Click Edit , then Paste .
9.
In c3, double-click Employee to display the source code.
 
Search WWH ::




Custom Search