Dr Java (java script) problem, why won't my check boxes show up?

the checkboxes won't show up by themselves or in a checkboxgroup. i've tried putting the intructions for the checkboxes in the (ItemEvent event) section in stead of the (Graphics screen) section, but that didn't work either, my programming teacher can't figure it out and neither can i.
here's the source code:

import java.awt.*;
import java.awt.event.*;
public class supex1604_2 extends java.applet.Applet implements ItemListener{
Graphics screen;
Choice mymenubar, mymenubar2;
Checkbox mybox1, mybox2;
CheckboxGroup mygroup;
Label headlabel, eyelabel;
String menuitem, menuitem2;
Color clr;
public void init() {
setLayout(null);
//drop menus
mymenubar=new Choice();
mymenubar.addItem("Oval");
mymenubar.addItem("Circle");
mymenubar.addItem("Square");
mymenubar.addItem("Rectangle");
mymenubar.addItemListener(this);
mymenubar.setBounds(10,80,75,30);
headlabel=new Label("Head Shape");
headlabel.setBounds(10,40,100,30);
add(mymenubar);
add(headlabel);
mymenubar2=new Choice();
mymenubar2.addItem("Square");
mymenubar2.addItem("Oval");
mymenubar2.addItemListener(this);
mymenubar2.setBounds(150,80,75,30);
eyelabel=new Label("Eye Shape");
eyelabel.setBounds(150,40,100,30);
add(mymenubar2);
add(eyelabel);

//checkboxes
mygroup=new CheckboxGroup();
mybox1=new Checkbox("Oval", mygroup, false);
mybox2=new Checkbox("Rectangle", mygroup, false);
mybox1.addItemListener(this);
mybox2.addItemListener(this);
add(mybox1);
add(mybox2);

}
public void itemStateChanged(ItemEvent event) {
repaint();
}

public void paint(Graphics screen) {
//head shape
screen.setColor(Color.black);
menuitem=mymenubar.getSelectedItem();
if(menuitem.equals("Oval")) {
screen.fillOval(100,200,200,100);}
else if(menuitem.equals("Circle")) {
screen.fillOval(100,150,200,200);}
else if(menuitem.equals("Square")) {
screen.fillRect(100,150,200,200);}
else if(menuitem.equals("Rectangle")) {
screen.fillRect(100,200,200,100);}

//eye shape
screen.setColor(Color.white);
menuitem2=mymenubar2.getSelectedItem();
if(menuitem2.equals("Oval")) {
screen.fillOval(150,220,30,50);
screen.fillOval(220,220,30,50);}
else if(menuitem2.equals("Square")) {
screen.fillRect(150,220,30,30);
screen.fillRect(220,220,30,30);}

//checkboxes
if(mybox1.getState()==true)
{screen.fillOval(150,120,30,50);}
if(mybox2.getState()==true)
{screen.fillRect(150,120,30,50);}
}
}


i've also tried putting the same instructions in a new program except without the menubars and everything else and it worked fine, so i'm not sure what the problem is
here's the source code for the one that does work:

import java.awt.*;
import java.awt.event.*;
public class ex1604_UNDEFINED extends java.applet.Applet implements ItemListener {
Graphics screen;
Checkbox mybox1, mybox2;
CheckboxGroup mygroup;
Color clr;
public void init() {
mygroup=new CheckboxGroup();
mybox1=new Checkbox("Oval", mygroup, false);
mybox2=new Checkbox("Rectangle", mygroup, false);
mybox1.addItemListener(this);
mybox2.addItemListener(this);
add(mybox1);
add(mybox2);
clr=Color.black;
}
public void itemStateChanged(ItemEvent event) {
repaint();
}

public void paint(Graphics screen) {
screen.setColor(clr);
if(mybox1.getState()==true)
{screen.fillOval(150,120,30,50);}
if(mybox2.getState()==true)
{screen.fillRect(150,120,30,50);}
}
}
 
Back
Top