package gradertool.gradebook; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DeleteGradedItem extends JFrame { /** * Construct this, per the design explained in the class comment. */ public DeleteGradedItem() { maxComponentHeight = 1.9; maxComponentWidth = 3000; panel = new JPanel(); add(panel); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); composeBox(); setTitle("Delete Graded Item"); pack(); } public void composeBox() { panel.add(Box.createVerticalStrut(15)); panel.add(addLabelRow()); panel.add(Box.createVerticalStrut(15)); panel.add(addComboBoxRow()); panel.add(Box.createVerticalStrut(15)); panel.add(composeButtonRow()); panel.add(Box.createVerticalStrut(15)); } protected Box addLabelRow(){ Box hbox = Box.createHorizontalBox(); JLabel label = new JLabel("Select a graded item to delete"); label.setForeground(Color.black); hbox.add(Box.createHorizontalStrut(15)); hbox.add(label); hbox.add(Box.createHorizontalStrut(15)); return hbox; } protected Box addComboBoxRow(){ Box hbox = Box.createHorizontalBox(); itemComboBox = new JComboBox(); itemComboBox.addItem("select a graded item"); itemComboBox.addItem(""); itemComboBox.addItem("Q1"); itemComboBox.addItem("M1"); itemComboBox.addItem("M2"); itemComboBox.addItem("Final"); itemComboBox.addItem("Program 1"); itemComboBox.addItem("Lab 1"); itemComboBox.setMaximumSize( new Dimension(maxComponentWidth, (int)(maxComponentHeight * itemComboBox.getFont().getSize()))); hbox.add(Box.createHorizontalStrut(15)); hbox.add(itemComboBox); hbox.add(Box.createHorizontalStrut(15)); return hbox; } protected Box composeButtonRow() { Box hbox = Box.createHorizontalBox(); JButton okButton = new JButton("Delete"); JButton cancelButton = new JButton("Cancel"); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Delete Graded Item button pressed."); } } ); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } } ); hbox.add(cancelButton); hbox.add(Box.createHorizontalStrut(30)); hbox.add(okButton); return hbox; } JPanel panel; JComboBox itemComboBox; int maxComponentWidth; double maxComponentHeight; }