package gradertool.gradebook; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * NewStudentDisplay */ public class NewStudentDisplay extends JFrame { /** * Construct this, per the design explained in the student requirements */ public NewStudentDisplay() { JPanel outerBox = new JPanel(); Box topBox = Box.createVerticalBox(); Box nameBox = Box.createHorizontalBox(); Box studentIDBox = Box.createHorizontalBox(); Box emplIDBox = Box.createHorizontalBox(); Box majorBox = Box.createHorizontalBox(); Box classLevelBox = Box.createHorizontalBox(); Box emailBox = Box.createHorizontalBox(); Box phoneBox = Box.createHorizontalBox(); //Box notesBox = Box.createVerticalBox(); Box notesBox1 = Box.createHorizontalBox(); Box notesBox2 = Box.createHorizontalBox(); Box buttonBox = Box.createHorizontalBox(); topBox.setPreferredSize(new Dimension(400, 450)); setContentPane(outerBox); nameBox.setAlignmentX(Component.RIGHT_ALIGNMENT); studentIDBox.setAlignmentX(Component.RIGHT_ALIGNMENT); emplIDBox.setAlignmentX(Component.RIGHT_ALIGNMENT); majorBox.setAlignmentX(Component.RIGHT_ALIGNMENT); classLevelBox.setAlignmentX(Component.RIGHT_ALIGNMENT); emailBox.setAlignmentX(Component.RIGHT_ALIGNMENT); phoneBox.setAlignmentX(Component.RIGHT_ALIGNMENT); notesBox1.setAlignmentX(Component.RIGHT_ALIGNMENT); notesBox2.setAlignmentX(Component.RIGHT_ALIGNMENT); buttonBox.setAlignmentX(Component.RIGHT_ALIGNMENT); // set up name box JLabel nameLabel = new JLabel("Name: "); JTextField nameTextField = new JTextField(); nameLabel.setForeground(Color.black); nameTextField.setMaximumSize(new Dimension(400, 25)); nameBox.add(nameLabel); nameBox.add(nameTextField); // set up student ID box JLabel studentIDLabel = new JLabel("Student ID: "); JTextField studentIDTextField = new JTextField(); studentIDLabel.setForeground(Color.black); studentIDTextField.setMaximumSize(new Dimension(400, 25)); studentIDBox.add(studentIDLabel); studentIDBox.add(studentIDTextField); // set up empl ID box JLabel emplIDLabel = new JLabel("Empl ID: "); JTextField emplIDTextField = new JTextField(); emplIDLabel.setForeground(Color.black); emplIDTextField.setMaximumSize(new Dimension(400, 25)); emplIDBox.add(emplIDLabel); emplIDBox.add(emplIDTextField); // set up major box JLabel majorLabel = new JLabel("Major: "); JTextField majorTextField = new JTextField(); majorLabel.setForeground(Color.black); majorTextField.setMaximumSize(new Dimension(400, 25)); majorBox.add(majorLabel); majorBox.add(majorTextField); // set up classLevel box JLabel classLevelLabel = new JLabel("Class Level: "); JComboBox classLevelComboBox = new JComboBox(); classLevelLabel.setForeground(Color.black); classLevelComboBox.addItem("Freshman"); classLevelComboBox.addItem("Sophomore"); classLevelComboBox.addItem("Junior"); classLevelComboBox.addItem("Senior"); classLevelComboBox.addItem("Grad"); classLevelComboBox.setMaximumSize(new Dimension(400, 25)); classLevelBox.add(classLevelLabel); classLevelBox.add(classLevelComboBox); // set up email box JLabel emailLabel = new JLabel("Email: "); JTextField emailTextField = new JTextField(); emailLabel.setForeground(Color.black); emailTextField.setMaximumSize(new Dimension(400, 25)); emailBox.add(emailLabel); emailBox.add(emailTextField); // set up phone box JLabel phoneLabel = new JLabel("Phone: "); JTextField phoneTextField = new JTextField(); phoneLabel.setForeground(Color.black); phoneTextField.setMaximumSize(new Dimension(400, 25)); phoneBox.add(phoneLabel); phoneBox.add(phoneTextField); // set up notes box JLabel notesLabel = new JLabel("Notes: "); JTextField notesTextField = new JTextField(); notesLabel.setForeground(Color.black); notesLabel.setMaximumSize(new Dimension(400, 25)); notesTextField.setMaximumSize(new Dimension(400, 150)); notesBox1.add(notesLabel); notesBox2.add(notesTextField); // set up buttons box (left to right) Button buttonCancel = new Button("Cancel"); buttonCancel.setMaximumSize(new Dimension(150, 50)); buttonBox.add(buttonCancel); Button buttonOkay = new Button("OK"); buttonOkay.setMaximumSize(new Dimension(150, 50)); buttonBox.add(buttonOkay); /*// set up period box JLabel periodLabel = new JLabel("Period: "); JComboBox periodComboBox = new JComboBox(); periodLabel.setForeground(Color.black); periodComboBox.addItem("Winter 2013"); periodComboBox.addItem("Fall 2012"); periodComboBox.addItem("Summer 2012"); periodComboBox.addItem("Spring 2012"); periodComboBox.addItem("Winter 2012"); periodComboBox.addItem("Fall 2011"); periodComboBox.setPreferredSize(new Dimension(200, 25)); periodBox.add(periodLabel); periodBox.add(periodComboBox); periodBox.add(Box.createHorizontalStrut(50)); // set up list box JLabel listLabel = new JLabel("Classes: "); DefaultListModel list = new DefaultListModel(); list.addElement("CSC 308-01"); list.addElement("CSC 308-02"); list.addElement("CSC 308-03"); list.addElement("CSC 308-04"); list.addElement("CSC 101-01"); list.addElement("CSC 101-02"); JList classList = new JList(list); listBox.setPreferredSize(new Dimension(300, 150)); listBox.add(listLabel); listBox.add(new JScrollPane(classList)); // set up buttons box (left to right) Button buttonCancel = new Button("Cancel"); buttonCancel.setMaximumSize(new Dimension(100, 35)); buttonBox.add(buttonCancel); Button buttonImport = new Button("Import"); buttonImport.setMaximumSize(new Dimension(100, 35)); buttonBox.add(buttonImport);*/ // set up login box (top to bottom) topBox.add(Box.createVerticalStrut(5)); topBox.add(nameBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(studentIDBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(emplIDBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(majorBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(classLevelBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(emailBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(phoneBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(notesBox1); topBox.add(notesBox2); topBox.add(Box.createVerticalStrut(5)); topBox.add(buttonBox); /*topBox.add(Box.createVerticalStrut(5)); topBox.add(periodBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(listBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(buttonBox); topBox.add(Box.createVerticalStrut(5));*/ // set up outer box (top to bottom) outerBox.add(Box.createHorizontalStrut(20)); outerBox.add(topBox); setTitle("Edit Student - CPE 308"); cancelButtonAction(buttonCancel); okayButtonAction(buttonOkay); pack(); } /** * Add the 'Cancel' button. */ protected void cancelButtonAction(Button buttonCancel) { buttonCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { /*NewClassUI newClassUI = new NewClassUI(); newClassUI.getNewClassDisplay().setVisible(true); setVisible(false);*/ System.out.println("Cancel button clicked"); } }); } /** * Add the 'OK' button. */ protected void okayButtonAction(Button buttonOkay) { buttonOkay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Print a message System.out.println("Okay button clicked"); } }); } }