Java GUI Programming Notes for Informatics Practices Students

RAD (Rapid Application Development) is a method of developing software by using ready-made tools and wizards. The tools are simply dragged to the screen to design the user interface.

NetBeans IDE is a free, open source, cross platform IDE (Integrated Development Environment) with built-in support for the Java programming language.

Inspector Window shows a hierarchy of all the components contained in the currently opened form.

An Event refers to the occurrence of an activity.

A Message is the information sent to the application.

A GUI in Java is created with at least 3 kinds of objects: components, events, and listeners.

An event is an object that gets generated when the user does something (such as mouse-click, etc.).

A control is also known as a widget.

In Java, the size measurements are in points or twips. It is equal to 1/1440 of an inch. It is the smallest measurement that can be adjusted.

Adding Frames

Right-click on the Project Name. Select New. Select JFrame Form.

Text Field

String name = TextField1.getText();
int count = Integer.parseInt(TextField1.getText());
TextField1.setText("GUI Programming");

Message Dialog

import javax.swing.JOptionPane;
JOptionPane.showMessageDialog(null, "Hello World");

Button

myButton.setText("Close");
String s = myButton.getText();
myButton.doClick();

Exit Button

System.exit(0);

Labels

myLabel.setText("Username");
String s = myLabel.getText();

Password Field

String p = new String(pwd.getPassword());

Text Area

myTextArea.setText("Hello World");
String text = myTextArea.getText();
myTextArea.setColumns(5);
myTextArea.setRows(3);
int r = myTextArea.getRows();
int c = myTextArea.getColumns();
myTextArea.append("more text");

Check Boxes

if(myCheckBox.isSelected())
System.out.println("Yes");
String s = myCheckBox.getText();
myCheckBox.setText("Cheese");

Radio Buttons

Firstly create a Titled Panel for placing the Radio Buttons. Then use JButtonGroup control to group radio buttons.
if(jRadioButton1.isSelected())
jLabel1.setText("Yes");
String s = jRadioButton1.getText();
jRadioButton.setText("Welcome");

Leave a Reply

%d bloggers like this: