原子一号
The number one of atom
posts - 6, comments - 0, trackbacks - 0, articles - 0
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
自扩展JTextField-1
Posted on 2006-10-19 15:02
迟到的鱼
阅读(200)
评论(0)
编辑
收藏
1
import
java.awt.
*
;
2
import
javax.swing.
*
;
3
import
javax.swing.text.
*
;
4
import
java.awt.event.
*
;
5
6
public
class
TextFieldDemo
extends
JFrame
7
{
8
public
TextFieldDemo()
9
{
10
11
Container contentPane
=
this
.getContentPane();
12
13
contentPane.setLayout(
new
FlowLayout());
14
DigitalText txtDigitalText
=
new
DigitalText(
10
,
10
);
15
contentPane.add(
new
JLabel(
"
文本框
"
));
16
contentPane.add(txtDigitalText);
17
18
19
pack();
20
setVisible(
true
);
21
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22
}
23
24
public
static
void
main(String args[])
25
{
26
TextFieldDemo frame
=
new
TextFieldDemo();
27
}
28
}
29
//
用户自定义类
30
class
DigitalText
extends
JTextField
31
{
32
int
len;
33
public
DigitalText(
int
len)
34
{
35
this
.len
=
len;
36
}
37
public
DigitalText(
int
column,
int
len)
38
{
39
40
super
(column);
41
this
.len
=
len;
42
}
43
public
DigitalText(String strText,
int
column,
int
len)
44
{
45
super
(strText,column);
46
this
.len
=
len;
47
}
48
protected
Document createDefaultModel()
49
{
50
return
new
DigitalTextDocument();
51
}
52
53
class
DigitalTextDocument
extends
PlainDocument
54
{
55
public
void
insertString(
int
offs, String str, AttributeSet a)
throws
BadLocationException
56
{
57
if
( str
==
null
)
return
;
58
if
((
this
.getLength()
+
str.length())
>
len)
59
return
;
60
super
.insertString(offs,str,a);
61
}
62
}
63
64
}
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © 迟到的鱼
日历
<
2006年10月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用链接
我的随笔
我的评论
我的参与
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2006年10月 (6)
相册
Java文件流
搜索
最新评论
阅读排行榜
1. Java文件流的封装(450)
2. 观感(212)
3. 自扩展JTextField-2(208)
4. 自扩展JTextField-1(200)
5. 向量-2(199)
评论排行榜
1. Java文件流的封装(0)
2. 观感(0)
3. 自扩展JTextField-2(0)
4. 自扩展JTextField-1(0)
5. 向量-2(0)