framedbarmeter.java

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

JAVA
37
字号
import objectdraw.*;import java.awt.*;// A FramedBarMeter displays a variable length rectangle on a// background framed by a distinct border.public class FramedBarMeter extends FramedDisplay {        // Space between the frame and the bar    private static final double INSET = BORDER + 2;        // The bar itself    private FilledRect bar;        // Maximum width bar that will fit    private double maxWidth;        // Create frame and bar filling a fraction of the display    public FramedBarMeter( double fraction,                           double x, double y,                           double width, double height,                           DrawingCanvas canvas ) {                super( x, y, width, height, canvas );                maxWidth = width - 2*INSET;        bar = new FilledRect( x + INSET,  y + INSET,                              maxWidth*fraction, height - 2*INSET,                              canvas );        bar.setColor(Color.blue);    }        // Change the fraction of the display filled by the bar    public void setFraction( double fraction) {        bar.setWidth( maxWidth*fraction );    }}

⌨️ 快捷键说明

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