当前位置: 代码迷 >> Java相关 >> [求助]为什么TetxField不能编辑了?
  详细解决方案

[求助]为什么TetxField不能编辑了?

热度:268   发布时间:2006-06-11 00:40:30.0
[求助]为什么TetxField不能编辑了?

import java.awt.*;
import java.awt.event.*;
public class canxu implements ActionListener{
static Font fnt=new Font("Serief",Font.BOLD,22);
static Frame frm=new Frame();
static Button bn=new Button("关闭");
static Label lb1=new Label("余额:");
static Label lb2=new Label("帐号:");
static Label lb3=new Label("户名:");
static Label lb4=new Label("开户日期:");
static Label lb5=new Label("帐户类型:");

static TextField tfd1=new TextField(14);
static TextField tfd2=new TextField(14);
static TextField tfd3=new TextField(14);
static TextField tfd4=new TextField(14);
static TextField tfd5=new TextField(14);



public canxu(){

frm.setLayout(null);//取消布局后TextField居然不能编辑了
frm.setBounds(250,200,350,400);
frm.setBackground(Color.lightGray);

lb1.setBounds(60,30,100,50);
tfd1.setBounds(110,40,200,30);
lb2.setBounds(60,90,100,50);
tfd2.setBounds(110,100,200,30);
lb3.setBounds(60,150,100,50);
tfd3.setBounds(110,160,200,30);
lb4.setBounds(0,210,160,50);
tfd4.setBounds(110,220,200,30);
lb5.setBounds(0,270,160,50);
tfd5.setBounds(110,280,200,30);
bn.setBounds(160,350,50,30);

frm.add(lb1);
frm.add(tfd1);
frm.add(lb2);
frm.add(tfd2);
frm.add(lb3);
frm.add(tfd3);
frm.add(lb4);
frm.add(tfd4);
frm.add(lb5);
frm.add(tfd5);
frm.add(bn);

lb1.setFont(fnt);
lb2.setFont(fnt);
lb3.setFont(fnt);
lb4.setFont(fnt);
lb5.setFont(fnt);

tfd1.setFont(fnt);
tfd2.setFont(fnt);
tfd3.setFont(fnt);
tfd4.setFont(fnt);
tfd5.setFont(fnt);

bn.setFont(fnt);
bn.addActionListener(this);
frm.setVisible(true);
}


public void actionPerformed(ActionEvent e){
frm.dispose();//关闭窗口并释放资源

}
public static void main(String args[]){
new canxu();
}
}

搜索更多相关的解决方案: TetxField  

----------------解决方案--------------------------------------------------------
你这个程序每个文本框都是可以编辑的
只不过你使用了setBounds()这个方法,它使得文本框的开头没有显示出来
所以,最好不要使用setBounds(),最好是使用布局管理器来管理你的窗口布局
----------------解决方案--------------------------------------------------------
但是用布局管理器来布局又不知怎么令各控键排列整齐.
----------------解决方案--------------------------------------------------------

当然不能只用一种布局管理器
要学会用很多种混合起来用
BorderLayout,FlowLayout,GridLayout,GrigBagLayout
只要掌握了上面四种,一般的布局应该不成问题,


----------------解决方案--------------------------------------------------------

为什么不可以用setBounds();怎么会产生上述情况。
还有,TextField()中的整型代表的是列数,它有什么作用。


----------------解决方案--------------------------------------------------------
  相关解决方案