新手求教一个很奇怪的问题
实在搞不懂,只是花括号位置的区别,这样是可以的package Test;
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Test{
public static void main(String args[])
{
MyFrame mf = new MyFrame(100,100,200,200);
}
}
class MyFrame extends JFrame{
public MyFrame(int x,int y,int w,int h)
{
this.setSize(w, h);
this.setLocation(x, y);
this.setVisible(true);
Button a = new Button("确定");
Button b = new Button("确");
Button c = new Button("定");
this.add(a);
this.add(b);
this.add(c);
this.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
}
}
但这样就出错了
package Test;
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Test{
public static void main(String args[])
{
MyFrame mf = new MyFrame(100,100,200,200);
}
}
class MyFrame extends JFrame{
public MyFrame(int x,int y,int w,int h)
{
this.setSize(w, h);
this.setLocation(x, y);
this.setVisible(true);
}
Button a = new Button("确定");
Button b = new Button("确");
Button c = new Button("定");
this.add(a);
this.add(b);
this.add(c);
this.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
}
请问这到底是怎么回事?