/*File ControlPanelGIF.java */ import java.awt.*; import java.applet.*; /** * This is the control panel for the Dice Class * * @author Charles Stanton * * @version November 20 1996 * */ public class ControlPanelGIF extends Panel{ Font f = new Font("TimesRoman", Font.BOLD,12); DiceGIF applet; //Panel topPanel = new Panel(); //Panel leftPanel = new Panel(); //Panel rightPanel = new Panel(); //Panel bottomPanel = new Panel(); GridBagLayout gbl = new GridBagLayout(); public CheckboxGroup nrolls_cbg = new CheckboxGroup(); public CheckboxGroup ndice_cbg = new CheckboxGroup(); int ndice; public ControlPanelGIF(DiceGIF applet){ this.applet=applet; setBackground(new Color(230,230,230)); setLayout(gbl); // GridBagConstraints gbc_rollem = new GridBagConstraints(); gbc_rollem.gridx = 0; gbc_rollem.gridy = 0; gbc_rollem.gridwidth=1; gbc_rollem.gridheight=1; Button rollem = new Button("Roll'em"); gbl.setConstraints(rollem, gbc_rollem); add(rollem); // GridBagConstraints gbc_clear = new GridBagConstraints(); gbc_clear.gridx =1; gbc_clear.gridy =0; gbc_clear.gridwidth=1; gbc_clear.gridheight=1; Button clear = new Button("Clear"); gbl.setConstraints(clear, gbc_clear); add(clear); // GridBagConstraints gbc_rolls = new GridBagConstraints(); gbc_rolls.anchor=gbc_rolls.WEST; gbc_rolls. gridx =0; gbc_rolls.gridy =1; gbc_rolls.gridwidth=1; gbc_rolls.gridheight=1; Label rolls = new Label("# Rolls"); gbl.setConstraints(rolls, gbc_rolls); add(rolls); // GridBagConstraints gbc_r1 = new GridBagConstraints(); gbc_r1.anchor=gbc_r1.WEST; gbc_r1.gridx =0; gbc_r1.gridy=2; gbc_r1.gridwidth=1; gbc_r1.gridheight=1; Checkbox r1 = new Checkbox("1",nrolls_cbg,true); gbl.setConstraints(r1, gbc_r1); add(r1); // GridBagConstraints gbc_r2= new GridBagConstraints(); gbc_r2.anchor=gbc_r2.WEST; gbc_r2.gridx = 0; gbc_r2.gridy=3; gbc_r2.gridwidth=1; gbc_r2.gridheight=1; Checkbox r2 = new Checkbox("10",nrolls_cbg,false); gbl.setConstraints(r2, gbc_r2); add(r2); // GridBagConstraints gbc_r3 = new GridBagConstraints(); gbc_r3.anchor=gbc_r3.WEST; gbc_r3.gridx=0; gbc_r3.gridy=4; gbc_r3.gridwidth=1; gbc_r3.gridheight=1; Checkbox r3 = new Checkbox("20",nrolls_cbg,false); gbl.setConstraints(r3, gbc_r3); add(r3); // GridBagConstraints gbc_r4 = new GridBagConstraints(); gbc_r4.anchor=gbc_r4.WEST; gbc_r4.gridx=0; gbc_r4.gridy=5; gbc_r4.gridwidth=1; gbc_r4.gridheight=1; Checkbox r4 = new Checkbox("100",nrolls_cbg,false); gbl.setConstraints(r4, gbc_r4); add(r4); // GridBagConstraints gbc_ndicel = new GridBagConstraints(); gbc_ndicel.gridx=1; gbc_ndicel.gridy=1; gbc_ndicel.gridwidth=1; gbc_ndicel.gridheight=1; Label ndicel = new Label("# Dice"); gbl.setConstraints(ndicel, gbc_ndicel); add(ndicel); // GridBagConstraints gbc_nd1 = new GridBagConstraints(); gbc_nd1.gridx=1; gbc_nd1.gridy=2; gbc_nd1.gridwidth=1; gbc_nd1.gridheight=1; Checkbox nd1 = new Checkbox("1",ndice_cbg,true); gbl.setConstraints(nd1, gbc_nd1); add(nd1); // GridBagConstraints gbc_nd2 = new GridBagConstraints(); gbc_nd2.gridx=1; gbc_nd2.gridy=3; gbc_nd2.gridwidth=1; gbc_nd2.gridheight=1; Checkbox nd2 = new Checkbox("2",ndice_cbg,false); gbl.setConstraints(nd2, gbc_nd2); add(nd2); // GridBagConstraints gbc_nd3 = new GridBagConstraints(); gbc_nd3.gridx=1; gbc_nd3.gridy=4; gbc_nd3.gridwidth=1; gbc_nd3.gridheight=1; Checkbox nd3 = new Checkbox("6",ndice_cbg, false); gbl.setConstraints(nd3, gbc_nd3); add(nd3); // GridBagConstraints gbc_nd4 = new GridBagConstraints(); gbc_nd4.gridx=1; gbc_nd4.gridy=5; gbc_nd4.gridwidth=1; gbc_nd4.gridheight=1; Checkbox nd4 = new Checkbox("9",ndice_cbg,false); gbl.setConstraints(nd4, gbc_nd4); add(nd4); } public boolean action(Event evt, Object arg) { int ndice; int nrolls=1; //number of dice rolls nrolls= Integer.valueOf(nrolls_cbg.getCurrent().getLabel()).intValue(); if (evt.target instanceof Button){ String buttonLabel; Button b; b = (Button) evt.target; buttonLabel=b.getLabel(); if (buttonLabel.equals("Clear")) { applet.clear(); } else { // assume "roll'em" was pushed applet.rollem(nrolls); } } else if (evt.target instanceof Checkbox){ //String groupname; Checkbox tcb; CheckboxGroup tcbg; tcb = (Checkbox) evt.target; tcbg = tcb.getCheckboxGroup(); if (tcbg.equals(ndice_cbg)) { applet.clear(); ndice=Integer.valueOf(ndice_cbg.getCurrent().getLabel()).intValue(); applet.ndice=ndice; //SEEMS LIKE A BAD IDEA! } } return true; } public void update() { //this.SumX=SumX; repaint(); } }