framedtext.java~

来自「书籍"Java_面向事件编程"的附带光盘代码」· JAVA~ 代码 · 共 53 行

JAVA~
53
字号
import objectdraw.*;import java.awt.*;// A FramedText object displays a specified text message on a// background framed by a distinct border.public class FramedText extends FramedDisplay {        // Colors used for the text    private static final Color TEXTCOLOR = Color.gray;    private static final Color HIGHLIGHTCOLOR = Color.red;        protected Text message;            // The message displayed        // Create a FramedText object displaying the text 'contents'    // at the position and with the dimensions specified.}    public FramedText( String contents, double x, double y,                       double width, double height,                       DrawingCanvas canvas) {                // construct the frame        super( x, y, width, height, canvas);                // Construct and appropriately position the message        message = new Text ( contents, x, y, canvas);        message.setColor( TEXTCOLOR );        positionContents();    }    // Position the message to center it in the frame    private void positionContents() {        message.moveTo( displayLeft(), displayTop() );        message.move( (displayWidth()-message.getWidth())/2,                      (displayHeight()-message.getHeight()) /2 );    }                // Change the font size used    public void setTextSize( int size) {        message.setFontSize( size );        positionContents();    }        // Highlight the display by changing the text color    public void highlight() {        message.setColor( HIGHLIGHTCOLOR );    }        // Restore the standard text color    public void unHighlight() {        message.setColor( TEXTCOLOR );    }    }

⌨️ 快捷键说明

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