java程序中 设置button的位置

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.util.EventListener;
public class fontTest extends Frame implements ActionListener{
Font font;

Button b1,b2,b3,b4;
TextArea text;
Panel p1,p2;
public fontTest(){
b1=new Button("个人信息查询");
b2=new Button("本月工资查询");
b3=new Button("本月考勤查询");
text=new TextArea("请点击需要查询的项目");

p1=new Panel();
p2=new Panel();

p1.setLayout(new FlowLayout());
p1.add(b1);
p1.add(b2);
p1.add(b3);

p2.add(text);
this.setLayout(new BorderLayout());
this.add(p1,BorderLayout.SOUTH);
this.add(p2,BorderLayout.CENTER);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

this.setSize(500,500);
this.setBackground(Color.BLUE);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand()=="个人信息查询"){
font=new Font("个人信息查询",Font.BOLD,12);
text.setFont(font);
text.setForeground(Color.darkGray);
}
else if(e.getActionCommand()=="本月工资查询"){
font=new Font("本月工资查询",Font.BOLD,12);
text.setFont(font);
text.setForeground(Color.darkGray);
}
else {
font=new Font("本月考勤查询",Font.BOLD,12);
text.setFont(font);
text.setForeground(Color.darkGray);
}

}
public static void main(String args[]){
fontTest ft=new fontTest();
}

}
以上是我的程序,请问各位高手 如何设置我那3个button在次界面的位置?在线等 急

第1个回答  推荐于2017-11-25
用setBounds。比如
你的this.setLayout(new BorderLayout());
this.add(p1,BorderLayout.SOUTH);
this.add(p2,BorderLayout.CENTER);
你可以改成:
this.add(p1);
this.add(p2);
p1.setBounds(50,50,100,100);
你就会看到p1在界面的变化了。。
然后自己琢磨setBounds的用法。。。本回答被提问者采纳
第2个回答  2008-06-21
先用dreamwear设置下BUTTON的位置,然后复制过去
第3个回答  2008-06-20
可以采用jButton.setBounds(new Rectangle( X1, X2, X3, X4))方法对按钮直接定位,其中X1、X2表示位置,X3、X4表示大小。具体你可以查阅资料和查找帮助文档!
第4个回答  2008-06-20
this.setLayout(new BorderLayout());
this.add(p1,BorderLayout.SOUTH);
this.add(p2,BorderLayout.CENTER);

这里就是设置按纽在布局里的显示位置咯.
好象你没写p3?

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网