String name = nameField.
getText();
Program :
String gender = [Link]() ?
import [Link].*; "Male" : "Female";
import [Link]; String maritalStatus =
[Link]() ? "Single" : "Married";
import [Link];
import [Link].*;
[Link]("Name: " + name);
[Link]("Gender: " + gender);
public class SwingFormExample {
[Link]("Marital Status: " +
public static void main(String[] args) {
maritalStatus);
JFrame frame = new JFrame("Swing Form
}
Example");
});
[Link](JFrame.EXIT_ON_
CLOSE);
[Link](nameLabel);
[Link](500, 600);
[Link](nameField);
[Link](new GridLayout(4, 2));
[Link](genderLabel);
[Link](maleRadio);
JLabel nameLabel = new JLabel("Name:");
[Link](new JLabel()); // Empty label for
JTextField nameField = new JTextField(); alignment
[Link](femaleRadio);
JLabel genderLabel = new JLabel("Gender:"); [Link](statusLabel);
JRadioButton maleRadio = new [Link](singleCheckBox);
JRadioButton("Male");
[Link](new JLabel()); // Empty label for
JRadioButton femaleRadio = new alignment
JRadioButton("Female");
[Link](marriedCheckBox);
ButtonGroup genderGroup = new
ButtonGroup(); [Link](new JLabel()); // Empty label for
alignment
[Link](maleRadio);
[Link](submitButton);
[Link](femaleRadio);
[Link](true);
JLabel statusLabel = new JLabel("Marital
Status:"); }
JCheckBox singleCheckBox = new }
JCheckBox("Single");
JCheckBox marriedCheckBox = new
JCheckBox("Married");
JButton submitButton = new
JButton("Submit");
[Link](new
ActionListener() {
public void actionPerformed(ActionEvent e) {
Practical 5
Output :
Conclusion :
In this Practical we understand that how to design a form
using basic swing components.
K S P A T