import java.awt.*;
import java.awt.event.*;public class TestcheckEvent
{
public static void main(String[] args)
{
TestcheckEvent te = new TestcheckEvent();
TestcheckEvent.MyFrame = te.new MyFrame();//提示这句访问不到MyFrame类
}

public class MyFrame extends Frame
{
TextArea ta;
public MyFrame()
{
Frame f = new Frame("Test");
f.setLayout(new BorderLayout(3,1));
Label lb = new Label("Ñ¡ÔñѧÀú");
ta = new TextArea();
f.add(lb);f.add(new MyPanel()); f.add(ta);
f.setSize(300,200);
f.setVisible(true);
}
}

public class MyPanel extends Panel implements ItemListener
{
public MyPanel()
{
Panel p = new Panel();
p.setLayout(new FlowLayout());
CheckboxGroup cbg = new CheckboxGroup();
Checkbox cb1 = new Checkbox("´óѧ±ÏÒµ",cbg,false);
Checkbox cb2 = new Checkbox("˶ʿ±ÏÒµÉú",cbg,false);
Checkbox cb3 = new Checkbox("²©Ê¿±ÏÒµÉú",cbg,false);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
p.add(cb1);p.add(cb2);p.add(cb3);
}

public void itemStateChanged(ItemEvent e)
{
System.out.println(e.getItem());
}
}
}

解决方案 »

  1.   

    TestcheckEvent.MyFrame t= te.new MyFrame();// 这样写!你应该声明一个实例名才是啊
      

  2.   

    TestcheckEvent.MyFrame mf = te.new MyFrame();
    问题解决了...
    但是为什么不显示panel组件啊?
      

  3.   

    组件覆盖了.
    这样:
    f.add(lb,BorderLayout.SOUTH);f.add(new MyPanel(),BorderLayout.NORTH); f.add(ta);
      

  4.   

    import java.awt.*;
    import java.awt.event.*;public class TestcheckEvent
    {
    public static void main(String[] args)
    {
    TestcheckEvent te = new TestcheckEvent();
    TestcheckEvent.MyFrame mf= te.new MyFrame();//提示这句访问不到MyFrame类
    }

    public class MyFrame extends Frame
    {
    TextArea ta;
    public MyFrame()
    {
    setLayout(new FlowLayout());
    Label lb = new Label("Ñ¡ÔñѧÀú");
    ta = new TextArea(5,22);
    add(lb);add(new MyPanel()); add(ta);
    setSize(400,300);
    setVisible(true);
    }
    }

    public class MyPanel extends Panel implements ItemListener
    {
    public MyPanel()
    {
    setLayout(new FlowLayout());
    CheckboxGroup cbg = new CheckboxGroup();
    Checkbox cb1 = new Checkbox("´óѧ±ÏÒµ",cbg,false);
    Checkbox cb2 = new Checkbox("˶ʿ±ÏÒµÉú",cbg,false);
    Checkbox cb3 = new Checkbox("²©Ê¿±ÏÒµÉú",cbg,false);
    cb1.addItemListener(this);
    cb2.addItemListener(this);
    cb3.addItemListener(this);
    add(cb1);add(cb2);add(cb3);
    }

    public void itemStateChanged(ItemEvent e)
    {
    System.out.println(e.getItem());
    }
    }
    }