<分区>
这可能是一个愚蠢的问题,但是如果您在类的构造函数中初始化一个新对象,或者您在类主体中初始化对象/变量,这有关系吗?
public class MyFrame extends JFrame {
private JButton button1;
private JButton button2;
public MyFrame(){
button1 = new JButton("Button1");
button2 = new JButton("Button2");
}
}
对比
public class MyFrame extends JFrame {
private JButton button1 = new JButton("Button1");
private JButton button2 = new JButton("Button2");
public MyFrame(){
}
}