1 INTRODUCTION NetBeans development environment ...

kaputmaltwormΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 4 μέρες)

291 εμφανίσεις

Java lab8. JFrame Form Application

NetBeans development environment enables quick creation of applications with GUI.
Choice New / File -> JFrame Form gives you the ability to design GUI. Putting component (Labels,
Buttons, TextFields, Panels, Menus etc.) in the JFrame Form can be done by dragging selected
components (controls) from the Palette window into the forms (using the mouse). For the currently
selected control, you can view (and modify) its properties, visible in the Properties window (Fig. 1.).
For example, a property:
• text is responsible for the text that appears on the components
• name is the name of the component object
• background is the background color
• foreground is the text color, etc.

By dragging components on form, the NetBeans automatically adds (to the source code) the components
variables that define the default setting for these properties (they can be changed either directly in code or
using the Properties window). The default name given to components are:
• for JButtons – variables are named jButton1, jBbutton2, ...
• for JLabels - variables are named jLabel1, jLabel2, ...
• for JTextFields - variables are named jTextField1, jTextField2, ...
• etc.

Fig.1. JFrame Form

The most important is the ability to define what should be done when an user performs some action (for
example: when the user clicks a button, chooses a menu item, presses Enter in a text field, enters the
mouse in the control area, etc.). After the event occurrence an event handler method is called. Usually the
simplest prototype of such a method (eg, clicking on the button) is created automatically when you
double click on a control in the forms. The window with the source code will be displayed, similar to that
as shown in Figure 2. The big red rectangle indicates the automatically generated method (with empty
body) associated with the click of a button named jButton1.
Java lab8. JFrame Form Application

e. The menu option Clear clears the TextArea (select the option and click the right mouse button - you
can choose an event for which will be automatically generated method eg, Events-> Mouse->
f. The menu option End exits the application:
5. Test the application.

Fig. 3. The additional fields and use of the ColorChooser in the jButton1ActionPerformed method

Fig. 4. Little Editor in action