public class mainFrame extends Frame
{
Label L1;
TextField T1;
Button B1; public mainFrame()
{
this.setLayout(null);

L1=new Label("输入您的代号");
L1.setBounds(40,50,80,25);
this.add(L1);
T1=new TextField("在这里输入",30);
T1.setBounds(125,50,90,25);
this.add(T1);
B1=new Button("Button1");
B1.setBounds(125,90,90,25);
B1.addMouseListener(new Button1Listener());
this.add(B1); this.setBackground(Color.yellow);
this.setBounds(0,0,250,220);
this.setTitle("Frame类示例");
this.addWindowListener(new WindowClose());
this.setVisible(true);
}
public static void main(String[] args)
{
mainFrame myframe=new mainFrame();
myframe.T1.setText("test");
}
};class Button1Listener extends MouseAdapter
{
public void mouseClicked(MouseEvent E)
{
JOptionPane.showMessageDialog(null,T1.getLable());
//这里报错,cannot find symbol
}
};class WindowClose extends WindowAdapter
{
public void windowClosing(WindowEvent E)
{
System.exit(0);
}
};

解决方案 »

  1.   


    public class mainFrame extends Frame
    {
    Label L1;
    public TextField T1;
    Button B1; public mainFrame()
    {
    this.setLayout(null);

    L1=new Label("输入您的代号");
    L1.setBounds(40,50,80,25);
    this.add(L1);
    T1=new TextField("在这里输入",30);
    T1.setBounds(125,50,90,25);
    this.add(T1);
    B1=new Button("Button1");
    B1.setBounds(125,90,90,25);
    B1.addMouseListener(new Button1Listener());
    this.add(B1); this.setBackground(Color.yellow);
    this.setBounds(0,0,250,220);
    this.setTitle("Frame类示例");
    this.addWindowListener(new WindowClose());
    this.setVisible(true);
    }
    public static void main(String[] args)
    {
    mainFrame myframe=new mainFrame();
    myframe.T1.setText("test");
    }
    };class Button1Listener extends MouseAdapter
    {
    public void mouseClicked(MouseEvent E)
    {
    JOptionPane.showMessageDialog(null,T1.getText());
    //这样也没用
    }
    };class WindowClose extends WindowAdapter
    {
    public void windowClosing(WindowEvent E)
    {
    System.exit(0);
    }
    };