📄 listing29.1.java
字号:
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 ) {
// add code here to respond to a change in a bound property
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -