郁闷,怎么找不到符号呢?
import java.awt.*;import java.awt.event.*;
public class TestDemo1
{
public static void main(String[] args)
{
new Frame1();
}
}
class Frame1 implements ActionListener
{
static final int Height1=300;
static final int Width1=500;
Frame1()
{
Frame f1=new Frame("this is the first frame");
f1.setSize(Width1,Height1);
f1.setVisible(true);
f1.setLayout(null);
Button btn1=new Button("test");
f1.add(btn1);
btn1.setBounds(30,30,30,30);
f1.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
btn1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
new Frame2();
}
}
}
class Frame2
{
static final int Height2=300;
static final int Width2=500;
Frame2()
{
Frame f2=new Frame("this is the second frame");
f2.setSize(Width2,Height2);
f2.setVisible(true);
Button btn2=new Button("test");
f2.add(btn2);
}
}
编译报错:
--------------------Configuration: TestDemo1 - JDK version <Default> - <Default>--------------------
E:\pro_files\JCreatorV4\MyProjects\TestDemo1\src\TestDemo1.java:41: 找不到符号
符号: 变量 btn1
位置: 类 Frame1
if(e.getSource()==btn1)
^
1 错误