java: could someone tell me whats wrong with this?
I've been learning java for a little bit and I am stuck on a specific piece of code. Could anyone tell me whats wrong with this?```markupimport java.awt.; import java.awt.event.; import java.applet.Applet;
class checkpanel extends Applet {
Checkbox ch1, ch2, ch3, ch4;
checkboxpanel() {
ch1 = new Checkbox("1");
add(ch1);
ch2 = new Checkbox("2");
add(ch2);
ch3 = new Checkbox("3");
add(ch3);
ch4 = new Checkbox("4");
add(ch4);
ch5 = new Checkbox("5");
add(ch5);
}
}```
EpsilonX wrote: I've been learning java for a little bit and I am stuck on a specific piece of code. Could anyone tell me whats wrong with this?```markupimport java.awt.; import java.awt.event.; import java.applet.Applet;
class checkpanel extends Applet {
Checkbox ch1, ch2, ch3, ch4;
checkboxpanel() {
ch1 = new Checkbox("1");
add(ch1);
ch2 = new Checkbox("2");
add(ch2);
ch3 = new Checkbox("3");
add(ch3);
ch4 = new Checkbox("4");
add(ch4);
ch5 = new Checkbox("5");
add(ch5);
}
}```
First off, ch5 isn't declared. Next, your class name is checkpanel (should be Checkpanel, or even CheckPanel for readability) and your method (I'm assuming its your constructor?) is called checkboxpanel(). If it is going to act as the constructor, it needs to have the same name as the class its in, and unless it is for a special purpose is usually declared as public. For example:
String var1;
public MyClass()
{
var1= "HBH";
}
}```