⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameddisplay.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;import java.awt.*;// A FramedDisplay is a composite graphic intended to serve// as a frame in which a program can display information.public class FramedDisplay {    private static final int BORDER = 3;    // Border thickness    private static final int ROUNDNESS = 5;   // Corner roundess        // Colors used for the frame    private static final Color BORDERCOLOR = Color.gray;    private static final Color HIGHLIGHTCOLOR = Color.red;        private FilledRoundedRect body;            // The background    private FilledRoundedRect border;        // The border    // Create the display area's background and border    public FramedDisplay( double x, double y,                          double width, double height,                          DrawingCanvas canvas)  {        border = new FilledRoundedRect( x, y, width, height,                                        ROUNDNESS, ROUNDNESS, canvas);        body = new FilledRoundedRect( x + BORDER, y + BORDER,                                      width-2*BORDER, height-2*BORDER,                                      ROUNDNESS, ROUNDNESS, canvas);        border.setColor( BORDERCOLOR );    }        // This method should be overriden by any subclass so    // it correctly positions the contents of the display    protected void positionContents(  ) {   }    // Change the border's color to make it stand out    public void highlight() {  border.setColor( HIGHLIGHTCOLOR ); }    // Restore the standard border color    public void unHighlight() { border.setColor( BORDERCOLOR );  }            // Return the x coord of the left edge of display area    protected double displayLeft() {    return body.getX();   }        // Return the y coord of the top edge of display area    protected double displayTop() {    return body.getY();    }        // Return the width of the display area    protected double displayWidth() { return body.getWidth();  }        // Return the height of the display area    protected double displayHeight() { return body.getHeight();  }    // move the parts of the framed display by offsets    public void move(double xoff, double yoff) {        border.move(xoff, yoff);        body.move(xoff, yoff);        positionContents();    }        // move the parts of the frame to a specific location    public void moveTo( double x, double y ) {        move( x - border.getX(), y - border.getY() );    }}

⌨️ 快捷键说明

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