Java按钮程序setBounds的问题
importjava.awt.*;publicclassButtonFrameextendsFrame{ButtonmyButton1,myButton2,myButto...
import java.awt.*;
public class ButtonFrame extends Frame
{Button myButton1,myButton2,myButton3,myButton4,myButton5;<br>public ButtonFrame(String str)<br>{super(str);<br>myButton1=new Button();<br>myButton2=new Button("Button2");<br>myButton1.setLabel("Button1");<br>myButton3=new Button("Button3");<br>myButton4=new Button("Button4");<br>myButton5=new Button("Button5");</p><p><br>this.add(myButton1);<br>myButton1.setBounds(50,50,50,50);<br>this.add(myButton2);<br>myButton2.setBounds(50,100,50,50);<br>this.add(myButton3);<br>myButton3.setBounds(50,150,50,50);<br>this.add(myButton4);<br>myButton4.setBounds(50,200,50,50);<br>this.add(myButton5);<br>myButton5.setBounds(50,250,50,50);</p><p>this.setSize(500,500);<br>this.setVisible(true);<br>}
public static void main(String args[])
{ButtonFrame f=new ButtonFrame("Button");<br>}
}这个是程序,按钮5总是会占满版面,其他没事。无论是增加还是减少 最后一个都是和现在这个按钮5一样的问题,请帮我看下那里出错!谢谢,在线等 展开
public class ButtonFrame extends Frame
{Button myButton1,myButton2,myButton3,myButton4,myButton5;<br>public ButtonFrame(String str)<br>{super(str);<br>myButton1=new Button();<br>myButton2=new Button("Button2");<br>myButton1.setLabel("Button1");<br>myButton3=new Button("Button3");<br>myButton4=new Button("Button4");<br>myButton5=new Button("Button5");</p><p><br>this.add(myButton1);<br>myButton1.setBounds(50,50,50,50);<br>this.add(myButton2);<br>myButton2.setBounds(50,100,50,50);<br>this.add(myButton3);<br>myButton3.setBounds(50,150,50,50);<br>this.add(myButton4);<br>myButton4.setBounds(50,200,50,50);<br>this.add(myButton5);<br>myButton5.setBounds(50,250,50,50);</p><p>this.setSize(500,500);<br>this.setVisible(true);<br>}
public static void main(String args[])
{ButtonFrame f=new ButtonFrame("Button");<br>}
}这个是程序,按钮5总是会占满版面,其他没事。无论是增加还是减少 最后一个都是和现在这个按钮5一样的问题,请帮我看下那里出错!谢谢,在线等 展开
1个回答
2013-08-01
展开全部
在this.add(myButton1);之前加一句:setLayout(null);表示frame不使用布局管理器,即可达到自定义布局的目的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询