第1个回答 2010-04-05
比如你窗体名称是f,按钮名称是b
f.setVisible(true);//设置窗体可见
f.setSize(300,300);//设置窗体大小
f.add(b);//把按钮添加进窗体
f.validate();//设置组件可见
这样就可以了。
第2个回答 2010-04-05
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class MyFrame extends JFrame {
public MyFrame() {
this.setSize(600,400);
this.setLayout(new FlowLayout());
JButton btn = new JButton("按钮");
this.add(btn);
this.setVisible(true);
}
public static void main(String[] args) {
new MyFrame();
}
}
第3个回答 2010-04-05
setVisible(true);
默认窗口是隐藏的
要把按钮加到窗口上,如果JFrame
getContentPane().add(myButton);
这样窗口显示的时候也会显示按钮
第4个回答 2010-04-06
Java的窗口默认是隐藏的
在窗口的构造函数中把按钮加到窗口上
this.add(按钮名);
this.setVisible(true);
第5个回答 2010-04-05
比如你窗体名称是f,按钮名称是b
f.setVisible(true);//设置窗体可见
f.setSize(300,300);//设置窗体大小
f.add(b);//把按钮添加进窗体
f.validate();//设置组件可见
这样就可以了。
第6个回答 2010-04-05
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class MyFrame extends JFrame {
public MyFrame() {
this.setSize(600,400);
this.setLayout(new FlowLayout());
JButton btn = new JButton("按钮");
this.add(btn);
this.setVisible(true);
}
public static void main(String[] args) {
new MyFrame();
}
}
第7个回答 2010-04-05
setVisible(true);
默认窗口是隐藏的
要把按钮加到窗口上,如果JFrame
getContentPane().add(myButton);
这样窗口显示的时候也会显示按钮
第8个回答 2010-04-06
Java的窗口默认是隐藏的
在窗口的构造函数中把按钮加到窗口上
this.add(按钮名);
this.setVisible(true);