// 2 points total for the imports import java.awt.*; import java.awt.event.*; // 2 points for extending Frame public class GUI extends Frame{ // 1 point for each widget Choice myChoice; Label myLabel; public GUI(){ // 2 point for the set size setSize(100, 100); // 2 points for the BorderLayout setLayout(new BorderLayout()); // 3 points for choice setup myChoice = new Choice(); myChoice.add("Red"); myChoice.add("Green"); myChoice.add("Blue"); // 1 point for label setup myLabel = new Label("Hello."); // 2 points for each addition add("North", myLabel); add("South", myChoice); // 2 points for each listener addition myChoice.addItemListener(new MyChoiceHandler()); addWindowListener(new MyWindowHandler()); } // 2 points for using an inner class which implements ItemListener protected class MyChoiceHandler implements ItemListener{ // 1 point for implementing the itemChanged method public void itemStateChanged(ItemEvent e){ // 1 point for setting the correct text myLabel.setText(myChoice.getSelectedItem()); } } // 2 points for a class that extends WindowAdapter // they can implement WindowListener but need to write all 7 methods protected class MyWindowHandler extends WindowAdapter{ // 1 point for implementing the windowClosing method public void windowClosing(WindowEvent e){ // 1point for the System.exit(0) System.exit(0); } } // 2 points for getting the main program right public static void main(String[] args){ new GUI().show(); // could also do this // GUI myGui = new GUI(); // myGui.show(); } }