import java.awt.*; import java.applet.*; import java.awt.event.*; // 1.1 public class RadioState extends Applet implements ActionListener { CheckboxGroup cbg = new CheckboxGroup(); Checkbox good = new Checkbox("Good", false, cbg); Checkbox better = new Checkbox("Better", false, cbg); Checkbox best = new Checkbox("Best", true, cbg); Button paintIt = new Button("Paint It"); public void init() { setLayout(new BorderLayout()); add("North", makeButtons()); add("South", paintIt); paintIt.addActionListener(this); } public void actionPerformed(ActionEvent ae) { Graphics g = getGraphics(); int w = getSize().width; int h = getSize().height; int ratio = 1; Checkbox current = cbg.getSelectedCheckbox(); if (current == good) ratio = 5; else if (current == better) ratio = 3; else if (current == best) ratio = 2; g.clearRect(0, 0, w, h); g.fillOval(w/2 - ((w/ratio)/2), h/2 - ((h/ratio)/2), w/ratio, h/ratio); g.dispose(); } public Panel makeButtons() { Panel p = new Panel(); p.setLayout(new GridLayout(1, 0, 5, 5)); p.add(good); p.add(better); p.add(best); Panel p2 = new Panel(); p2.add(p); return p2; } }