TextFields汉.docx
- 文档编号:17829856
- 上传时间:2023-08-04
- 格式:DOCX
- 页数:19
- 大小:21.94KB
TextFields汉.docx
《TextFields汉.docx》由会员分享,可在线阅读,更多相关《TextFields汉.docx(19页珍藏版)》请在冰点文库上搜索。
TextFields汉
java.awt
类TextField
java.lang.Object
java.awt.Component
java.awt.TextComponent
java.awt.TextField
所有已实现的接口:
ImageObserver,MenuContainer,Serializable,Accessible
publicclassTextField
extendsTextComponent
TextField对象是允许编辑单行文本的文本组件。
例如,下图描绘了带有四个宽度各异的文本字段的窗体。
其中两个文本字段显示预定义文本"Hello"。
以下是产生四个文本字段的代码:
TextFieldtf1,tf2,tf3,tf4;
//ablanktextfield
tf1=newTextField();
//blankfieldof20columns
tf2=newTextField("",20);
//predefinedtextdisplayed
tf3=newTextField("Hello!
");
//predefinedtextin30columns
tf4=newTextField("Hello",30);
每次用户在文本字段中键入一个键时,就有一个或更多键事件被发送到该文本字段。
KeyEvent是以下三种类型之一:
keyPressed、keyReleased或keyTyped。
键事件的属性指示事件是哪一种类型,以及关于事件的其他信息,比如对键事件应用哪种修饰符和事件发生的时间。
键事件被传递给每一个KeyListener或KeyAdapter对象,这些对象使用组件的addKeyListener方法注册,以接收这类事件。
(KeyAdapter对象实现KeyListener接口。
)
TextField还可能触发ActionEvent。
如果对文本字段启用操作事件,则可以通过按下Return键触发它们。
TextField类的processEvent方法检查操作事件,并将它们传递给processActionEvent。
后一种方法将该事件重定向到为接收此文本字段生成的操作事件而注册的所有ActionListener对象。
从以下版本开始:
JDK1.0
另请参见:
KeyEvent,KeyAdapter,KeyListener,ActionEvent,Component.addKeyListener(java.awt.event.KeyListener),processEvent(java.awt.AWTEvent),processActionEvent(java.awt.event.ActionEvent),addActionListener(java.awt.event.ActionListener),序列化表格
嵌套类摘要
protected class
TextField.AccessibleAWTTextField
此类实现TextField类的可访问性支持。
从类java.awt.TextComponent继承的嵌套类/接口
TextComponent.AccessibleAWTTextComponent
从类java.awt.Component继承的嵌套类/接口
Component.AccessibleAWTComponent,Component.BaselineResizeBehavior,Component.BltBufferStrategy,Component.FlipBufferStrategy
字段摘要
从类java.awt.TextComponent继承的字段
textListener
从类java.awt.Component继承的字段
BOTTOM_ALIGNMENT,CENTER_ALIGNMENT,LEFT_ALIGNMENT,RIGHT_ALIGNMENT,TOP_ALIGNMENT
从接口java.awt.image.ImageObserver继承的字段
ABORT,ALLBITS,ERROR,FRAMEBITS,HEIGHT,PROPERTIES,SOMEBITS,WIDTH
构造方法摘要
TextField()
构造新文本字段。
TextField(int columns)
构造具有指定列数的新空文本字段。
TextField(String text)
构造使用指定文本初始化的新文本字段。
TextField(String text,int columns)
构造使用要显示的指定文本初始化的新文本字段,宽度足够容纳指定列数。
方法摘要
void
addActionListener(ActionListener l)
添加指定的操作侦听器,以从此文本字段接收操作事件。
void
addNotify()
创建TextField的同位体。
boolean
echoCharIsSet()
指示此文本字段是否有一个回显字符集。
AccessibleContext
getAccessibleContext()
获取与此TextField关联的AccessibleContext。
ActionListener[]
getActionListeners()
返回此文本字段上已注册的所有操作侦听器的数组。
int
getColumns()
获取此文本字段中的列数。
char
getEchoChar()
获取用于回显的字符。
T[]
getListeners(Class
返回当前已在此TextField上注册为FooListener的所有对象的数组。
Dimension
getMinimumSize()
获取此文本字段的最小尺寸。
Dimension
getMinimumSize(int columns)
获取具有指定列数的文本字段的最小尺寸。
Dimension
getPreferredSize()
获取此文本字段的首选大小。
Dimension
getPreferredSize(int columns)
获取具有指定列数的文本字段的首选大小。
Dimension
minimumSize()
已过时。
从JDKversion1.1开始,由getMinimumSize()取代。
Dimension
minimumSize(int columns)
已过时。
从JDKversion1.1开始,由getMinimumSize(int)取代。
protected String
paramString()
返回表示此TextField状态的字符串。
Dimension
preferredSize()
已过时。
从JDKversion1.1开始,由getPreferredSize()取代。
Dimension
preferredSize(int columns)
已过时。
从JDKversion1.1开始,由getPreferredSize(int)取代。
protected void
processActionEvent(ActionEvent e)
处理发生在此文本字段上的操作事件:
将这些事件指派给所有已注册的ActionListener对象。
protected void
processEvent(AWTEvent e)
处理此文本字段上的事件。
void
removeActionListener(ActionListener l)
移除指定的操作侦听器,不再从此文本字段接收操作事件。
void
setColumns(int columns)
设置此文本字段中的列数。
void
setEchoChar(char c)
设置此文本字段的回显字符。
void
setEchoCharacter(char c)
已过时。
从JDKversion1.1开始,由setEchoChar(char)取代。
void
setText(String t)
将此文本组件显示的文本设置为指定文本。
从类java.awt.TextComponent继承的方法
addTextListener,enableInputMethods,getBackground,getCaretPosition,getInputMethodRequests,getSelectedText,getSelectionEnd,getSelectionStart,getText,getTextListeners,isEditable,processTextEvent,removeNotify,removeTextListener,select,selectAll,setBackground,setCaretPosition,setEditable,setSelectionEnd,setSelectionStart
从类java.awt.Component继承的方法
action,add,addComponentListener,addFocusListener,addHierarchyBoundsListener,addHierarchyListener,addInputMethodListener,addKeyListener,addMouseListener,addMouseMotionListener,addMouseWheelListener,addPropertyChangeListener,addPropertyChangeListener,applyComponentOrientation,areFocusTraversalKeysSet,bounds,checkImage,checkImage,coalesceEvents,contains,contains,createImage,createImage,createVolatileImage,createVolatileImage,deliverEvent,disable,disableEvents,dispatchEvent,doLayout,enable,enable,enableEvents,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,firePropertyChange,getAlignmentX,getAlignmentY,getBaseline,getBaselineResizeBehavior,getBounds,getBounds,getColorModel,getComponentAt,getComponentAt,getComponentListeners,getComponentOrientation,getCursor,getDropTarget,getFocusCycleRootAncestor,getFocusListeners,getFocusTraversalKeys,getFocusTraversalKeysEnabled,getFont,getFontMetrics,getForeground,getGraphics,getGraphicsConfiguration,getHeight,getHierarchyBoundsListeners,getHierarchyListeners,getIgnoreRepaint,getInputContext,getInputMethodListeners,getKeyListeners,getLocale,getLocation,getLocation,getLocationOnScreen,getMaximumSize,getMouseListeners,getMouseMotionListeners,getMousePosition,getMouseWheelListeners,getName,getParent,getPeer,getPropertyChangeListeners,getPropertyChangeListeners,getSize,getSize,getToolkit,getTreeLock,getWidth,getX,getY,gotFocus,handleEvent,hasFocus,hide,imageUpdate,inside,invalidate,isBackgroundSet,isCursorSet,isDisplayable,isDoubleBuffered,isEnabled,isFocusable,isFocusCycleRoot,isFocusOwner,isFocusTraversable,isFontSet,isForegroundSet,isLightweight,isMaximumSizeSet,isMinimumSizeSet,isOpaque,isPreferredSizeSet,isShowing,isValid,isVisible,keyDown,keyUp,layout,list,list,list,list,list,locate,location,lostFocus,mouseDown,mouseDrag,mouseEnter,mouseExit,mouseMove,mouseUp,move,nextFocus,paint,paintAll,postEvent,prepareImage,prepareImage,print,printAll,processComponentEvent,processFocusEvent,processHierarchyBoundsEvent,processHierarchyEvent,processInputMethodEvent,processKeyEvent,processMouseEvent,processMouseMotionEvent,processMouseWheelEvent,remove,removeComponentListener,removeFocusListener,removeHierarchyBoundsListener,removeHierarchyListener,removeInputMethodListener,removeKeyListener,removeMouseListener,removeMouseMotionListener,removeMouseWheelListener,removePropertyChangeListener,removePropertyChangeListener,repaint,repaint,repaint,repaint,requestFocus,requestFocus,requestFocusInWindow,requestFocusInWindow,reshape,resize,resize,setBounds,setBounds,setComponentOrientation,setCursor,setDropTarget,setEnabled,setFocusable,setFocusTraversalKeys,setFocusTraversalKeysEnabled,setFont,setForeground,setIgnoreRepaint,setLocale,setLocation,setLocation,setMaximumSize,setMinimumSize,setName,setPreferredSize,setSize,setSize,setVisible,show,show,size,toString,transferFocus,transferFocusBackward,transferFocusUpCycle,update,validate
从类java.lang.Object继承的方法
clone,equals,finalize,getClass,hashCode,notify,notifyAll,wait,wait,wait
构造方法详细信息
TextField
publicTextField()
throwsHeadlessException
构造新文本字段。
抛出:
HeadlessException-如果GraphicsEnvironment.isHeadless()返回true。
另请参见:
GraphicsEnvironment.isHeadless()
TextField
publicTextField(String text)
throwsHeadlessException
构造使用指定文本初始化的新文本字段。
参数:
text-要显示的文本。
如果text为null,则显示空字符串""。
抛出:
HeadlessException-如果GraphicsEnvironment.isHeadless()返回true。
另请参见:
GraphicsEnvironment.isHeadless()
TextField
publicTextField(int columns)
throwsHeadlessException
构造具有指定列数的新空文本字段。
列是近似平均字符宽度,它与平台有关。
参数:
columns-列数。
如果columns小于0,则将columns设置为0。
抛出:
HeadlessException-如果GraphicsEnvironment.isHeadless()返回true。
另请参见:
GraphicsEnvironment.isHeadless()
TextField
publicTextField(String text,
int columns)
throwsHeadlessException
构造使用要显示的指定文本初始化的新文本字段,宽度足够容纳指定列数。
列是近似平均字符宽度,它与平台有关。
参数:
text-要显示的文本。
如果text为null,则显示空字符串""。
columns-列数。
如果columns小于0,则将columns设置为0。
抛出:
HeadlessException-如果GraphicsEnvironment.isHeadless()返回true。
另请参见:
GraphicsEnvironment.isHeadless()
方法详细信息
addNotify
publicvoidaddNotify()
创建TextField的同位体。
此同位体允许修改TextField的外观,并且不更改其功能。
覆盖:
类TextComponent中的addNotify
另请参见:
TextComponent.removeNotify()
getEchoChar
publicchargetEchoChar()
获取用于回显的字符。
回显字符对于不应将用户输入回显到屏幕上的文本字段有用,例如输入密码的文本字段。
如果echoChar=0,则将用户输入不作更改地回显到屏幕。
Java平台实现只能支持有限的、非空回显字符集。
此函数返回setEchoChar()最初请求的回显字符。
TextField实现实际使用的回显字符可能不同。
返回:
此文本字段的回显字符。
另请参见:
echoCharIsSet(),setEchoChar(char)
setEchoChar
publicvoidsetEchoChar(char c)
设置此文本字段的回显字符。
回显字符对于不应将用户输入回显到屏幕上的文本字段很有用,例如输入密码的文本字段。
设置echoChar=0允许将用户输入再次回显到屏幕。
Java平台实现只能支持有限的、非空回显字符集。
试图设置不受支持的回显字符将导致使用默认回显字符。
对getEchoChar()的后续调用将返回最初请求的回显字符。
返回的回显字符有可能与TextField实现实际使用的相同,也有可能不同。
参数:
c-此文本字段的回显字符。
从以下版本开始:
JDK1.1
另请参见:
echoCharIsSet(),getEchoChar()
setEchoCharacter
@Deprecated
publicvoidsetEchoCharacter(char c)
已过时。
从JDKversion1.1开始,由setEchoChar(char)取代。
setText
publicvoidsetText(String t)
将此文本组件显示的文本设置为指定文本。
覆盖:
类TextComponent中的setText
参数:
t-新文本。
另请参见:
TextComponent.getText()
echoCharIsSet
publicbooleanechoCharIsS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TextFields