📄 abstracttextfield.java
字号:
/*====================================================================*\AbstractTextField.javaAbstract text field class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage textfield;//----------------------------------------------------------------------// IMPORTSimport java.awt.Color;import javax.swing.JTextField;//----------------------------------------------------------------------// ABSTRACT TEXT FIELD CLASSpublic abstract class AbstractTextField extends JTextField{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// private static final Color DEFAULT_INVALID_BACKGROUND_COLOUR = new Color( 240, 192, 192 );////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// protected AbstractTextField( ) { invalidBackgroundColour = DEFAULT_INVALID_BACKGROUND_COLOUR; } //------------------------------------------------------------------ protected AbstractTextField( int columns ) { super( columns ); invalidBackgroundColour = DEFAULT_INVALID_BACKGROUND_COLOUR; } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : overriding methods//////////////////////////////////////////////////////////////////////// public Color getBackground( ) { return ( invalid ? invalidBackgroundColour : (isEnabled( ) || (disabledBackgroundColour == null)) ? super.getBackground( ) : disabledBackgroundColour ); } //------------------------------------------------------------------ public void setText( String text ) { invalid = false; super.setText( text ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods//////////////////////////////////////////////////////////////////////// public boolean isEmpty( ) { try { return ( getText( ).length( ) == 0 ); } catch ( NullPointerException e ) { return true; } } //------------------------------------------------------------------ public boolean isInvalid( ) { return invalid; } //------------------------------------------------------------------ public Color setDisabledBackgroundColour( ) { return disabledBackgroundColour; } //------------------------------------------------------------------ public Color getInvalidBackgroundColour( ) { return invalidBackgroundColour; } //------------------------------------------------------------------ public void setInvalid( boolean invalid ) { if ( this.invalid != invalid ) { this.invalid = invalid; repaint( ); } } //------------------------------------------------------------------ public void setDisabledBackgroundColour( Color colour ) { if ( ((disabledBackgroundColour == null) && (colour != null)) || ((disabledBackgroundColour != null) && !disabledBackgroundColour.equals( colour )) ) { disabledBackgroundColour = colour; repaint( ); } } //------------------------------------------------------------------ public void setInvalidBackgroundColour( Color colour ) { if ( !invalidBackgroundColour.equals( colour ) ) { invalidBackgroundColour = colour; repaint( ); } } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance variables//////////////////////////////////////////////////////////////////////// private boolean invalid; private Color disabledBackgroundColour; private Color invalidBackgroundColour;}//----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -