Java GUI Programming Notes for Informatics Practices Students

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");