Article View: cn.bbs.comp.lang.java
Article #21569Java ͼ���û��������4�ı���������������
From: ����è->�ú�ѧϰ...
Date: Thu, 27 Nov 2003 16:39
Date: Thu, 27 Nov 2003 16:39
91 lines
7488 bytes
7488 bytes
��. �ı���������������
�����ı������������֣������ı������ (JTextField) �Ͷ����ı������ (JTextA
rea)�������������ֻ��һ�� (JPasswordField)��JPasswordField �� JTextField ��
���࣬���ǵ���Ҫ����� JPasswordField ������ʾ���û�����Ķ�������ֻ����ʾ��
����Ա�趨��һ���̶��ַ���� '*'��
���������ʾ��ͼ�ʹ����� JTextField��JPasswordField �� JTextArea ��ʾ��
/**
* TestTexts.java
* @author Fancy
*/
import javax.swing.*;
import javax.swing.event.*;
public class TestTexts extends JFrame {
private JLabel label = new JLabel("Status");
private JTextField textField;
private JPasswordField pwdField;
private JTextArea textArea;
public TestTexts() {
super("Test Texts");
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());
textField = new JTextField(15);
/* �����ı�����ƶ��¼� */
textField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
// ���ı������ݣ��Ϳ��Լ�ʱ���� label ��ʾ������
label.setText(textField.getText());
}
});
pwdField = new JPasswordField(15);
pwdField.setEchoChar('#');
textArea = new JTextArea(5, 15);
textArea.setLineWrap(true);
getContentPane().add(textField);
getContentPane().add(pwdField);
getContentPane().add(textArea);
getContentPane().add(label);
setSize(200, 200);
}
public static void main(String[] args) {
TestTexts tt = new TestTexts();
tt.show();
}
}
���������У����ǹ�����һ�����Ϊ 15 ���ַ�ĵ����ı��� (textField = new JTex
tField(15);)����ʹ�� addCaretListener ���������һ�� CaretListener (textFiel
d.addCaretListener ...)��CaretListener �����ı������ƶ��¼������û�ʹ�ü���
�������ƶ����ı������ JTextField �е�λ��ʱ��������¼���������Ҫ���� car
etUpdate(CaretEvent e) ���¼����д��� (public void caretUpdate(CaretEvent e)
...)���������ǿ��������������� VB �� TextBox �� OnChange �¼����������顣
����JTextField �� 5 �����췽�����������е��ĸ���
����JTextField()
����JTextField(int columns)�������� textField = new JTextField(15);
����JTextField(String text)
����JTextField(String text, int columns)
�������У����� text �ǵ����ı���ij�ʼ���ݣ��� columns ָ���˵����ı���Ŀ��
�����ַ�Ϊ��λ��JTextField �е��ı����ݿ����� getText() ������á�Ҳ������ s
etText ����ָ�� JTextField �е��ı����ݡ�
����JPasswordField �� JTextField �����࣬�乹�췽��Ҳ�����Ƶġ�JPasswordFiel
d �ṩ�� setEchoChar(char ch) ��������Ϊ�������������ʾ���ַ�Ĭ��Ϊ '*' ��
��������������Ϊ�� '#' �ַ� (pwdField.setEchoChar('#');)���� JTextField һ
��JPasswordField Ҳ�� getText ������ setText ��û��������ı����� (��Ȼ����
�������������ص�)��
����JTextField �ǵ����ı�������ʾ�����ı��������Ҫ��ʾ�����ı�����ֻ��ʹ
�ö����ı��� JTextArea �ˡ�JTextArea ��������췽�������õ�Ҳ���ĸ���
����JTextArea()
����JTextArea(int rows, int columns)
����JTextArea(String text)
����JTextArea(String text, int rows, int columns)��
����text Ϊ JTextArea �ij�ʼ���ı����ݣ�rows Ϊ JTextArea �ĸ߶ȣ�����Ϊ��λ
��columns Ϊ JTextArea �Ŀ�ȣ����ַ�Ϊ��λ���������о�����һ���� 5 �У���
15 ���ַ�Ķ����ı��� (textArea = new JTextArea(5, 15);)��
���������ı���Ĭ���Dz����Զ����е� (�����������س�����)�����ǿ���ʹ�� JT
extArea �� setLineWrap ���������Ƿ������Զ����С�setLineWrap(true) �������Զ�
���У�setLineWrap(false) ���Dz������Զ����С������ı�������û������������
����չ��С�����ţ��Լ�����ʵ�顪������Զ����У���ô�����ı���Ŀ�����
��һ������ȷ���ģ��������ݳ�����Ԥ�������������ı������չ����ĸ߶�ȥ
��Ӧ�����仰˵�������ı����Զ��������������ô�죿���潲���������� (JScr
ollPane) ��ʱ�����֪���ˡ�
���������ı������ı����ݵĻ�ú����ã�ͬ�����ʹ�� getText �� setText ������
������ɡ�
--
���������ʱ������㰮����һ���ˣ����㣬���㣬һ��Ҫ����ضԴ��������
�����֣�ҲҪ�úõ�˵���ټ������Ժ���Ż�֪��������Ȼ����ɲ�ǣ�û��Թ��
�ഺ�Ż������ź�����ɽ�������־��������¡���
���� -----ϯĽ��
[23��1H
[m[1;31m�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 211.80.91.3][m
Technical Details
Message-ID:
<49QaP7$AWG@bbs.sjtu.edu.cn>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!SJTUShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: f6cb0,7fabbbf7f813af8e,start X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2003-11-27 08:36:03 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!SJTU From: bocoo.bbs@bbs.sjtu.edu.cn (����è->�ú�ѧϰ...) Newsgroups: cn.bbs.comp.lang.java Subject: Java ͼ���û��������4�ı��������������� Date: 27 Nov 2003 16:39:34 GMT Organization: ��ˮ˼Դ Message-ID: <49QaP7$AWG@bbs.sjtu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: Java/M.1069951159.A