java的gui设计中的元件大小问题 在框架中插入一个按钮后,如何设置这个按钮的大小呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import java.awt.event.*;public class Taskwork implements TextListener,ActionListener{ Frame f; TextField tf; public static void main(String args[]) { new Taskwork(); } public Taskwork() { f=new Frame("Task work!"); f.setLayout(new GridBagLayout()); f.addWindowListener(new WindowEventHandler()); tf=new TextField("",25); tf.addTextListener(this); tf.addActionListener(this); Button b[]=new Button[24]; int a[][]=new int[30][]; for(int i=1;i<5;i++) { for(int j=0;j<6;j++) { a[j+i*6]=new int[]{j,i,1,1,0,0}; } } a[0]=new int[]{0,0,6,1,0,0}; add(f,tf,a[0]); abb(f,b[0],a[6],"MC"); abb(f,b[1],a[7],"7"); abb(f,b[2],a[8],"8"); abb(f,b[3],a[9],"9"); abb(f,b[4],a[10],"/"); abb(f,b[5],a[11],"sqrt"); abb(f,b[6],a[12],"MR"); abb(f,b[7],a[13],"4"); abb(f,b[8],a[14],"5"); abb(f,b[9],a[15],"6"); abb(f,b[10],a[16],"*"); abb(f,b[11],a[17],"%"); abb(f,b[12],a[18],"MS"); abb(f,b[13],a[19],"1"); abb(f,b[14],a[20],"2"); abb(f,b[15],a[21],"3"); abb(f,b[16],a[22],"-"); abb(f,b[17],a[23],"1/x"); abb(f,b[18],a[24],"M+"); abb(f,b[19],a[25],"0"); abb(f,b[20],a[26],"+/-"); abb(f,b[21],a[27],"."); abb(f,b[22],a[28],"+"); abb(f,b[23],a[29],"="); f.setSize(200,200); f.setVisible(true); } private static void add(Container con, Component com, int[] is) { GridBagConstraints cons=new GridBagConstraints(); cons.gridheight=is[3]; cons.gridwidth=is[2]; cons.gridx=is[0]; cons.gridy=is[1]; cons.weightx=is[4]; cons.weighty=is[5]; con.add(com,cons); } private static void abb(Frame f,Button b,int[] is,String s){ b=new Button(s); add(f, b, is); } @Override public void textValueChanged(TextEvent arg0) { // TODO Auto-generated method stub } @Override public void actionPerformed(ActionEvent arg0) { tf.setText(""); }}不知道怎么能改变按钮的大小,谁能告诉我啊? 循环问题 编码问题 ★★★关于LIST内对象引用的一点困惑★★★ 新手急求!IO效率 求救:用socket做的广播,客户端一直收不到信息啊?? 父类子类构造问题,诚问 怎么获得抽象类的对象 JAVA的系统 超级菜鸟问题----赚分啦 问两个简单的问题? js字符大小比较大家帮忙侃侃 我不知道怎么改了,找大虾帮修改下,急!!先谢谢了!!!!!
import java.awt.event.*;
public class Taskwork implements TextListener,ActionListener{
Frame f;
TextField tf;
public static void main(String args[])
{
new Taskwork();
}
public Taskwork()
{
f=new Frame("Task work!");
f.setLayout(new GridBagLayout());
f.addWindowListener(new WindowEventHandler());
tf=new TextField("",25);
tf.addTextListener(this);
tf.addActionListener(this);
Button b[]=new Button[24];
int a[][]=new int[30][];
for(int i=1;i<5;i++)
{
for(int j=0;j<6;j++)
{
a[j+i*6]=new int[]{j,i,1,1,0,0};
}
}
a[0]=new int[]{0,0,6,1,0,0};
add(f,tf,a[0]);
abb(f,b[0],a[6],"MC");
abb(f,b[1],a[7],"7");
abb(f,b[2],a[8],"8");
abb(f,b[3],a[9],"9");
abb(f,b[4],a[10],"/");
abb(f,b[5],a[11],"sqrt");
abb(f,b[6],a[12],"MR");
abb(f,b[7],a[13],"4");
abb(f,b[8],a[14],"5");
abb(f,b[9],a[15],"6");
abb(f,b[10],a[16],"*");
abb(f,b[11],a[17],"%");
abb(f,b[12],a[18],"MS");
abb(f,b[13],a[19],"1");
abb(f,b[14],a[20],"2");
abb(f,b[15],a[21],"3");
abb(f,b[16],a[22],"-");
abb(f,b[17],a[23],"1/x");
abb(f,b[18],a[24],"M+");
abb(f,b[19],a[25],"0");
abb(f,b[20],a[26],"+/-");
abb(f,b[21],a[27],".");
abb(f,b[22],a[28],"+");
abb(f,b[23],a[29],"=");
f.setSize(200,200);
f.setVisible(true);
} private static void add(Container con, Component com, int[] is) {
GridBagConstraints cons=new GridBagConstraints();
cons.gridheight=is[3];
cons.gridwidth=is[2];
cons.gridx=is[0];
cons.gridy=is[1];
cons.weightx=is[4];
cons.weighty=is[5];
con.add(com,cons);
}
private static void abb(Frame f,Button b,int[] is,String s){
b=new Button(s);
add(f, b, is);
}
@Override
public void textValueChanged(TextEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent arg0) {
tf.setText("");
}
}不知道怎么能改变按钮的大小,谁能告诉我啊?