import java.awt.Button;
import java.awt.Color;import java.awt.Frame;
public class TSButton { public static void main(String[] args) {
new pt("TestButton",300,300,400,400,Color.cyan);
// Button b = new Button("press me!");
//p.add(b); }}
class pt extends Frame{
Button b; pt(String s,int x,int y,int w,int h,Color c){
super(s); b = new Button("press me!");
b.setVisible(true);
add(b); b = new Button("press me!");
b.setVisible(true);
add(b);
setBackground(c);
setLayout(null);
setBounds(x,y,w,h);
setVisible(true);
}
}
import java.awt.Color;import java.awt.Frame;
public class TSButton { public static void main(String[] args) {
new pt("TestButton",300,300,400,400,Color.cyan);
// Button b = new Button("press me!");
//p.add(b); }}
class pt extends Frame{
Button b; pt(String s,int x,int y,int w,int h,Color c){
super(s); b = new Button("press me!");
b.setVisible(true);
add(b); b = new Button("press me!");
b.setVisible(true);
add(b);
setBackground(c);
setLayout(null);
setBounds(x,y,w,h);
setVisible(true);
}
}
b = new Button("press me!");
b.setVisible(true);//不用
你用的是setLayout(null);
需要给button 设置大小位置
或者改流式布局
setLayout(new FlowLayout());
b.setVisible(true);
你设置不可见了 当然看不到
setVisible(true)是可见LZ,你把布局设置了null,那么按钮要设置他的bound属性才行
还有button的visible默认就是true了
import java.awt.Color;
import java.awt.Frame;public class TSButton { public static void main(String[] args) {
new pt("TestButton", 300, 300, 400, 400, Color.cyan); }}class pt extends Frame {
Button b; pt(String s, int x, int y, int w, int h, Color c) { super(s); b = new Button("press me!");
add(b); b = new Button("press me!"); b.setLocation(50, 60);
b.setSize(100, 100);
add(b);
setBackground(c);
setLayout(null);
setBounds(x, y, w, h);
setVisible(true); }}
------------这样可以实现-----------