DL1997 2017-06-09 04:25 采纳率: 33.3%
浏览 2476

java button 的大小为什么没变。

public class Myframe extends Frame{
public void LaunchFrame(){
setSize(500,500);
setLocation(200,200);
setVisible(true);

    Button b = new Button("开始");
    b.setSize(10,10);
    add(b);


    new Threader().start();

    addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    }); 
}

public void paint(Graphics g){
    g.drawRect(100, 100, 300, 300);


}

class Threader extends Thread{
    public void run(){
        while(true){
            repaint();
            try {
                Thread.sleep(40);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }
}
public static void main(String args[]){
    Myframe my = new Myframe();
    my.LaunchFrame();

}

}
图片说明

  • 写回答

2条回答 默认 最新

  • 战在春秋 2017-06-09 04:56
    关注
       .............
        Button b = new Button("开始");
        b.setSize(10,10);
        add(b);
            ............
    

    修改为:

        ...............
        Button b = new Button("开始");
            setLayout( null ); //这行必不可少
            b.setBounds(100, 150, 50, 25); //设置按钮的大小位置
            add(b);
            ............
    

    其它部分不变。

    用心回答每个问题,如果有帮助,请采纳答案好吗,非常感谢~~。

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置