import objectdraw.*; import java.awt.*; import java.awt.event.*; public class DemoChoice extends WindowController implements ItemListener, ActionListener { private Text school; private Choice fontSizeChoice; private Checkbox panthers, cyclones, hawkeyes; private Button colorButton, schoolButton; public void begin() { school = new Text("UNI Panthers", 50, 100, canvas); school.setBold(); school.setFontSize(32); fontSizeChoice = new Choice(); fontSizeChoice.add("16"); fontSizeChoice.add("22"); fontSizeChoice.add("32"); fontSizeChoice.add("48"); fontSizeChoice.add("64"); fontSizeChoice.select("32"); add( fontSizeChoice, BorderLayout.NORTH ); fontSizeChoice.addItemListener( this ); colorButton = new Button("Color UNI Panthers"); add( colorButton, BorderLayout.EAST ); colorButton.addActionListener( this ); addSchoolPanel(); } public void itemStateChanged(ItemEvent evt) { int fontSize; fontSize = Integer.parseInt( fontSizeChoice.getSelectedItem() ); school.setFontSize( fontSize ); } public void actionPerformed(ActionEvent event) { if (event.getSource() == colorButton) { Color c; c = school.getColor(); if (c.getRed() > 128) { school.setColor( Color.blue ); colorButton.setLabel("Make it RED"); } else { school.setColor( Color.red ); colorButton.setLabel("Make it BLUE"); } } else if (event.getSource() == schoolButton) { String t = ""; if (panthers.getState()) t = "UNI Panthers"; else if (cyclones.getState()) t = "ISU Cyclones"; else if (hawkeyes.getState()) t = "Iowa Hawkeyes"; school.setText( t ); } } private void addSchoolPanel() { Panel radioButtonPanel = new Panel(); CheckboxGroup checks = new CheckboxGroup(); panthers = new Checkbox("Panthers", true, checks); cyclones = new Checkbox("Cyclones", false, checks); hawkeyes = new Checkbox("Hawkeyes", false, checks); radioButtonPanel.add(panthers); radioButtonPanel.add(cyclones); radioButtonPanel.add(hawkeyes); schoolButton = new Button("Change School Message"); radioButtonPanel.add(schoolButton); add (radioButtonPanel, BorderLayout.SOUTH); schoolButton.addActionListener (this); } }