textdisplayer.java

来自「java 完全探索的随书源码」· Java 代码 · 共 87 行

JAVA
87
字号
import java.awt.*;import java.beans.*;public class TextDisplayer extends Canvas implements PropertyChangeListener {   // default constructor for this Bean.  This is the constructor that an   // application builder (such as Visual Basic) would use.   public TextDisplayer() {      this( "TextDisplayer", Color.white,            new Font( "Courier", Font.PLAIN, 12 ), Color.black );   }   // custom constructor for this Bean.  This is the constructor you would   // likely use if you were going to do all your coding from scratch.   public TextDisplayer( String OutputText, Color BGColor, Font TextFont,                         Color FontColor ) {      this.OutputText = OutputText;      this.BGColor = BGColor;      this.TextFont = TextFont;      this.FontColor = FontColor;      setFont( TextFont );        // set the Canvas's font.      setBackground( BGColor );   // set the Canvas's background color.      setForeground( FontColor ); // set the Canvas's foreground color.   }   // this Bean's properties.   protected String OutputText;   protected Color BGColor, FontColor;   protected Font TextFont;   // override the Canvas's paint method to display the text   public void paint( Graphics g ) {     // simplistic implementation to display a string     g.drawString( OutputText, 10, 20 );   }   // implement the PropertyChangeListener interface   public void propertyChange( PropertyChangeEvent evt ) {     // only interested in the inputText property of TextReader     if ( evt.getPropertyName().equals("inputText") ) {       // display the new value of the TextReader property       setOutputText( (String)evt.getNewValue() );     }   }   public synchronized String getOutputText() {      return( OutputText );   }   public synchronized void setOutputText( String text ) {      OutputText = text;      // force a paint      Graphics g = getGraphics();      if ( g != null ) {        update(g);      }   }   public synchronized Color getBGColor() {      return BGColor;   }   public synchronized void setBGColor( Color color ) {      BGColor = color;      setBackground( BGColor );   // set the Canvas's background color.      repaint();   }   public synchronized Font getTextFont() {      return TextFont;   }   public synchronized void setTextFont( Font font ) {      TextFont = font;      setFont( TextFont );        // set the Canvas's font.   }   public synchronized Color getFontColor() {      return FontColor;   }   public synchronized void setFontColor( Color color ) {      FontColor = color;      setForeground( FontColor ); // set the Canvas's foreground color.      repaint();   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?