java seteditable,Java TextField.setEditable方法代碼示例

这段代码展示了如何使用Java创建一个用户界面,用于显示和操作数据库字段。它涉及到了TextField、Checkbox、Button等组件的布局,并根据数据库字段类型动态生成输入控件。同时,还实现了按钮事件监听,允许用户进行记录导航、添加、更新和清除操作。
摘要由CSDN通过智能技术生成

import java.awt.TextField; //導入方法依賴的package包/類

public void setupDBFields(String dbname) throws Exception

{

viewPane.setLayout(null);

Dimension dimView = sp.getSize();

int height = 0, width = 50;

viewPane.removeAll();

db = new DBF(dbname);

setTitle(dbname);

gb = new GridBagLayout();

gbc = new GridBagConstraints();

viewPane.setLayout(gb);

int i, j;

fldObjects = new Vector(db.getFieldCount());

for (i = 1; i <= db.getFieldCount(); i++)

{

j = i - 1;

f = db.getField(i);

if (f.isMemoField() || f.isPictureField()) {

b = new Button(db.getField(i).getName());

b.addActionListener(this);

addComponent(viewPane, b, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

fldObjects.addElement(b);

}

else if (f.getType() == 'L') {

c = new Checkbox(db.getField(i).getName(), true);

addComponent(viewPane, c, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

fldObjects.addElement(c);

}

else {

l = new Label(db.getField(i).getName(), Label.RIGHT);

addComponent(viewPane, l, 0, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

int ln = f.getLength();

if (ln > 100) ln = 100;

t = new TextField(db.getField(i).getName(), ln);

if (width < ln*10) width=ln*10;

addComponent(viewPane, t, 1, j, ln, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

fldObjects.addElement(t);

t.setEditable(true);

}

height += 10;

}

crl.setText("Record " + db.getCurrentRecordNumber());

trl.setText(" of " + db.getRecordCount());

SBrecpos.setMaximum(db.getRecordCount());

addComponent(viewPane, crl, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

addComponent(viewPane, trl, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

i++;

addComponent(viewPane, SBrecpos, 0, i, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

addComponent(viewPane, delCB, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST );

i++;

addComponent(viewPane, Prev, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

addComponent(viewPane, Next, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

i++;

addComponent(viewPane, Add, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

addComponent(viewPane, Update, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

addComponent(viewPane, Clear, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);

Prev.setEnabled(false);

prevRecord.setEnabled(false);

if (db.getRecordCount() == 0) {

Update.setEnabled(false);

updateRecord.setEnabled(false);

Next.setEnabled(false);

nextRecord.setEnabled(false);

}

dimView.setSize(width+150, height+150);

sp.setSize(dimView);

goTo(1);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值