NAME: MUTHEE DUNCAN CHERUIYOT
REG NO: CT101/G/16054/22
UNIT: OOP II
ASSIGNMENT
write a GUI interface that can Capture your name (Fname, Lname) Age, gender, Country of Origin, and
should have a button for ok and cancel using Grid layout.
import [Link].*;
import [Link].*;
public class UserInformationGUI extends JFrame {
private JTextField firstNameField, lastNameField, ageField, genderField,
countryField;
public UserInformationGUI() {
setTitle("User Information");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(6, 2));
[Link](new JLabel("First Name:"));
firstNameField = new JTextField();
[Link](firstNameField);
[Link](new JLabel("Last Name:"));
lastNameField = new JTextField();
[Link](lastNameField);
[Link](new JLabel("Age:"));
ageField = new JTextField();
[Link](ageField);
[Link](new JLabel("Gender:"));
genderField = new JTextField();
[Link](genderField);
[Link](new JLabel("Country of Origin:"));
countryField = new JTextField();
[Link](countryField);
JButton okButton = new JButton("OK");
[Link](e -> {
// Add logic to process captured user information
String firstName = [Link]();
String lastName = [Link]();
int age = [Link]([Link]());
String gender = [Link]();
String country = [Link]();
// Process the captured information here
});
[Link](okButton);
JButton cancelButton = new JButton("Cancel");
[Link](e -> [Link](0));
[Link](cancelButton);
add(panel);
pack();
setVisible(true);
}
public static void main(String[] args) {
new UserInformationGUI();
}
}