package gradertool.gradebook; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * CreateDisplay */ public class CreateDisplay extends JFrame { /** * Construct this, per the design explained in the class comment. */ public CreateDisplay() { JPanel outerBox = new JPanel(); Box topBox = Box.createVerticalBox(); Box buttonBox = Box.createHorizontalBox(); Box editBox = Box.createHorizontalBox(); Box nameBox = Box.createHorizontalBox(); Box periodBox = Box.createHorizontalBox(); Box listBox = Box.createVerticalBox(); topBox.setPreferredSize(new Dimension(400, 400)); setContentPane(outerBox); buttonBox.setAlignmentX(Component.RIGHT_ALIGNMENT); nameBox.setAlignmentX(Component.RIGHT_ALIGNMENT); periodBox.setAlignmentX(Component.RIGHT_ALIGNMENT); listBox.setAlignmentX(Component.RIGHT_ALIGNMENT); // set up name box JLabel nameLabel = new JLabel("Class Name: "); JTextField nameTextField = new JTextField(); nameLabel.setForeground(Color.black); nameTextField.setPreferredSize(new Dimension(200, 25)); nameBox.add(nameLabel); nameBox.add(nameTextField); nameBox.add(Box.createHorizontalStrut(50)); // set up period box JLabel yearLabel = new JLabel("Year: "); JTextField yearTextField = new JTextField(); yearLabel.setForeground(Color.black); yearTextField.setPreferredSize(new Dimension(100, 25)); JLabel periodLabel = new JLabel("Period: "); JComboBox periodComboBox = new JComboBox(); periodLabel.setForeground(Color.black); periodComboBox.addItem("Fall"); periodComboBox.addItem("Winter"); periodComboBox.addItem("Spring"); periodComboBox.addItem("Summer"); periodComboBox.setPreferredSize(new Dimension(100, 25)); periodBox.add(yearLabel); periodBox.add(yearTextField); periodBox.add(Box.createHorizontalStrut(5)); periodBox.add(periodLabel); periodBox.add(periodComboBox); periodBox.add(Box.createHorizontalStrut(50)); // set up list box JLabel listLabel = new JLabel("Students: "); String[] headers = {"Name", "ID"}; Object[][] data = { {"Cait Rahm", "crahm"}, {"Sally Miller", "smill"}, {"William Dugger", "wdugger"}, {"Doug Guastaferro", "dguastaf"}, {"Steve Johnson", "sjohnson"} }; JTable table = new JTable(data, headers); table.setFillsViewportHeight(true); listBox.add(listLabel); listBox.add(new JScrollPane(table)); // set up student buttons box Button addButton = new Button("Add"); Button editButton = new Button("Edit"); Button deleteButton = new Button("Delete"); editBox.setPreferredSize(new Dimension(200, 40)); editBox.add(addButton); editBox.add(Box.createHorizontalStrut(5)); editBox.add(editButton); editBox.add(Box.createHorizontalStrut(5)); editBox.add(deleteButton); // set up buttons box (left to right) Button buttonCancel = new Button("Cancel"); buttonCancel.setPreferredSize(new Dimension(60, 50)); buttonBox.add(buttonCancel); Button buttonOK = new Button("OK"); buttonOK.setPreferredSize(new Dimension(60, 50)); buttonBox.add(buttonOK); // set up login box (top to bottom) topBox.add(Box.createVerticalStrut(5)); topBox.add(nameBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(periodBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(listBox); topBox.add(Box.createVerticalStrut(5)); topBox.add(editBox); 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("Create New Class"); addButtonAction(addButton); editButtonAction(editButton); deleteButtonAction(deleteButton); cancelButtonAction(buttonCancel); okButtonAction(buttonOK); 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); } }); } /** * Add the 'OK' button. */ protected void okButtonAction(Button buttonOK) { buttonOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GradeSpreadsheetUI gSheet = new GradeSpreadsheetUI(); gSheet.getGradeSpreadsheetDisplay().setVisible(true); setVisible(false); } }); } /** * Add the 'Add' button. */ protected void addButtonAction(Button buttonAdd) { buttonAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { NewStudentDisplay newStudentDisplay = new NewStudentDisplay(); newStudentDisplay.setVisible(true); } }); } /** * Add the 'Edit' button. */ protected void editButtonAction(Button buttonEdit) { buttonEdit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { NewStudentDisplay newStudentDisplay = new NewStudentDisplay(); newStudentDisplay.setVisible(true); } }); } /** * Add the 'Delete' button. */ protected void deleteButtonAction(Button buttonDelete) { buttonDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Delete Student Clicked"); } }); } }