Create a program that simulates the student information management. After user e
ID: 3777356 • Letter: C
Question
Create a program that simulates the student information management. After user enters the information, the "Submit" button will store the student's information; when we click the "Show Student Info" button, the student's information will be displayed; while when we click the "Modify" button, a second window will pop up and the student's information will be filled automatically. After the student's information modification, we click the "Submit'' button in the second window, then the second windows disappears and the new student's information will be filled in the first window automatically. Student name: Jacksmith Student namel Student ID 012 Student ID: Student Age: Student Age Name: Jack Smith, ID: 0123456788, AgExplanation / Answer
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
/**
*
* @author paramesh
*/
public class StudentGUI extends JFrame {
private JPanel contentPane;
private JTextField nameTextField;
private JTextField IDTextField;
private JTextField AgeTextField;
private JTextArea result;
// main
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StudentGUI frame = new StudentGUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public StudentGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
SpringLayout sl_contentPane = new SpringLayout();
contentPane.setLayout(sl_contentPane);
nameTextField = new JTextField();
sl_contentPane.putConstraint(SpringLayout.NORTH, nameTextField, 10,
SpringLayout.NORTH, contentPane);
sl_contentPane.putConstraint(SpringLayout.WEST, nameTextField, 62,
SpringLayout.WEST, contentPane);
contentPane.add(nameTextField);
nameTextField.setColumns(10);
IDTextField = new JTextField();
sl_contentPane.putConstraint(SpringLayout.NORTH, IDTextField, 16,
SpringLayout.SOUTH, nameTextField);
sl_contentPane.putConstraint(SpringLayout.WEST, IDTextField, 0,
SpringLayout.WEST, nameTextField);
contentPane.add(IDTextField);
IDTextField.setColumns(10);
AgeTextField = new JTextField();
sl_contentPane.putConstraint(SpringLayout.NORTH, AgeTextField, 16,
SpringLayout.SOUTH, IDTextField);
sl_contentPane.putConstraint(SpringLayout.WEST, AgeTextField, 50,
SpringLayout.WEST, IDTextField);
contentPane.add(AgeTextField);
AgeTextField.setColumns(10);
result = new JTextArea();
sl_contentPane.putConstraint(SpringLayout.NORTH, result, 80,
SpringLayout.SOUTH, nameTextField);
sl_contentPane.putConstraint(SpringLayout.WEST, result, 30,
SpringLayout.WEST, nameTextField);
contentPane.add(result);
result.setColumns(10);
JLabel lblName = new JLabel("Student Name");
sl_contentPane.putConstraint(SpringLayout.NORTH, lblName, 10,
SpringLayout.NORTH, contentPane);
sl_contentPane.putConstraint(SpringLayout.EAST, lblName, 17,
SpringLayout.WEST, nameTextField);
contentPane.add(lblName);
JLabel lblStudentID = new JLabel("Student ID");
sl_contentPane.putConstraint(SpringLayout.NORTH, lblStudentID, 0,
SpringLayout.NORTH, IDTextField);
sl_contentPane.putConstraint(SpringLayout.EAST, lblStudentID, -6,
SpringLayout.WEST, IDTextField);
contentPane.add(lblStudentID);
JLabel lblStudentAge = new JLabel("Student Age");
sl_contentPane.putConstraint(SpringLayout.NORTH, lblStudentAge, 36,
SpringLayout.NORTH, IDTextField);
sl_contentPane.putConstraint(SpringLayout.EAST, lblStudentAge, 10,
SpringLayout.WEST, IDTextField);
contentPane.add(lblStudentAge);
JButton btnSubmit = new JButton("Submit");
sl_contentPane.putConstraint(SpringLayout.NORTH, btnSubmit, 100,
SpringLayout.SOUTH, IDTextField);
sl_contentPane.putConstraint(SpringLayout.WEST, btnSubmit, 100,
SpringLayout.WEST, contentPane);
contentPane.add(btnSubmit);
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String res = nameTextField.getText() + ", " + IDTextField.getText() + ", " + AgeTextField.getText();
result.setText("");
result.setText(res);
}
});
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.