import java.awt.*;
import java.awt.event.*;
class CheckboxGroupExample extends WindowAdapter implements ItemListener{
Frame f;
Panel p;
CheckboxGroup cbg;
TextField tf;
public static void main (String [] args){
CheckboxGroupExample ce = new CheckboxGroupExample();
ce.go();
}
public void go(){
f = new Frame("CheckboxGroup Example");
p = new Panel();
cbg = new CheckboxGroup();
one = new Checkbox("One",cbg,false);
two = new Checkbox("Two",cbg,false);
three = new Checkbox("Three",cbg,true);
one.addItemListener(this);
two.addItemListener(this);
three.addItemListener(this);
p.add(one);
p.add(two);
p.add(three);
f.add(p,"Center");
tf = new TextField();
tf.setText("Three selected");
f.add(tf,"South");
f.addWindowListener(this);
f.setSize(300,150);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
String st;
st = e.getItem()+"selected";
tf.setText(st);
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
一个书上的上的程序我运行时出现找不到符号 one two three 的错误! 请各位高手帮我解答 谢谢!!!
----------------解决方案--------------------------------------------------------
你都没有声明这三个组件,怎么找得到呢?
[此贴子已经被作者于2006-8-26 1:02:25编辑过]
----------------解决方案--------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class CheckboxGroupExample extends WindowAdapter implements ItemListener{
Frame f;
Panel p;
CheckboxGroup cbg;
Checkbox one,two,three;//在这里声明三个组件后,应该没什么问题了
TextField tf;
public static void main (String [] args){
CheckboxGroupExample ce = new CheckboxGroupExample();
ce.go();
}
public void go(){
f = new Frame("CheckboxGroup Example");
p = new Panel();
cbg = new CheckboxGroup();
one = new Checkbox("One",cbg,false);
two = new Checkbox("Two",cbg,false);
three = new Checkbox("Three",cbg,true);
one.addItemListener(this);
two.addItemListener(this);
three.addItemListener(this);
p.add(one);
p.add(two);
p.add(three);
f.add(p,"Center");
tf = new TextField();
tf.setText("Three selected");
f.add(tf,"South");
f.addWindowListener(this);
f.setSize(300,150);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
String st;
st = e.getItem()+"selected";
tf.setText(st);
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
[此贴子已经被作者于2006-8-26 1:02:48编辑过]
----------------解决方案--------------------------------------------------------
改了 还是不能运行 而且类型不兼容啊 你那样声明变量不对吧
----------------解决方案--------------------------------------------------------
好了 已经解决了 刚才失误了 谢谢2楼的 呵呵~ 就是那样改 呵呵~
----------------解决方案--------------------------------------------------------