这是我写的一段代码:
import javax.swing.*;
public class Information extends JFrame{
public Information(){
this.setLocation(450,300);
this.setSize(200,100);
this.setVisible(true);
JPanel p = new JPanel();
JButton b = new JButton("牛逼");
p.add(b);
this.add(p);
}
public static void main(String [] args)
{
Information in = new Information();
}
}
我在用dos运行时,可以正常运行,但是如果在Eclipse中运行不能显示出按钮,不知道是什么原因!
import javax.swing.*;
public class Information extends JFrame{
public Information(){
this.setLocation(450,300);
this.setSize(200,100);
this.setVisible(true);
JPanel p = new JPanel();
JButton b = new JButton("牛逼");
p.add(b);
this.add(p);
}
public static void main(String [] args)
{
Information in = new Information();
}
}
我在用dos运行时,可以正常运行,但是如果在Eclipse中运行不能显示出按钮,不知道是什么原因!
把this.setVisible(true);放最后吧
我以前听说国 AWT掩盖Swing的 而且作过测试确实
因为AWT是重量级的总是显示在上面
把this.setVisible(true);放最后