Topic: 帮忙看下这个初级代码

  Print this page

1.帮忙看下这个初级代码 Copy to clipboard
Posted by: itzy
Posted on: 2004-11-24 13:44

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ZH extends JFrame
{
public ZH()
{
setTitle("转换");
Container con=getContentPane();
con.setLayout(new GridLayout(2,2));

JLabel l1=new JLabel("原身份证号");
JLabel l2=new JLabel("转换后的身份证号");

JTextField t1=new JTextField(20);
JTextField t2=new JTextField(20);

con.add(l1);con.add(t1);con.add(l2);con.add(t2);

setSize(300,150);
setVisible(true);
}

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


怎样给t1,t2注册监听?
JTextField有几个方法?

2.Re:帮忙看下这个初级代码 [Re: itzy] Copy to clipboard
Posted by: aurorean
Posted on: 2004-11-25 16:27

你需要定义自己的TextField类,继承JTextField,覆盖JTextField的createDefaultModel()。

定义自己的Document模型(在createDefaultModel方法中返回该模型的一个实例),继承自PlainDocument,覆盖AbstractDocument的insertString(int offs, String str, AttributeSet a)。在该方法中对用户往TextField里输入的内容进行实时控制,比如限制输入的长度,允许输入什么等。

3.Re:帮忙看下这个初级代码 [Re: itzy] Copy to clipboard
Posted by: miaomiao9527
Posted on: 2004-11-25 22:04

用addationlistener( )方法注册
JFrame 有一个方法

4.Re:帮忙看下这个初级代码 [Re: itzy] Copy to clipboard
Posted by: k704790
Posted on: 2004-11-27 14:09

See the JDK doc is the best way

5.Re:帮忙看下这个初级代码 [Re: itzy] Copy to clipboard
Posted by: riceboy0309
Posted on: 2004-11-30 08:51

加一个Actionlistener,对Jtextfield进行监视,你这里最好加个按扭!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923