framedbarmeter.java
来自「书籍"Java_面向事件编程"的附带光盘代码」· Java 代码 · 共 47 行
JAVA
47 行
import objectdraw.*;import java.awt.*;public class FramedBarMeter extends FramedDisplay{ // Space between the frame and the bar private static final double INSET=2; // The bar itself private FilledRect bar; // Fraction currently being displayed private double fraction; // Create frame and bar filling a fraction of the display public FramedBarMeter( double aFraction, double x, double y, double width, double height, DrawingCanvas canvas) { super( x, y, width, height, canvas ); fraction = aFraction; bar = new FilledRect( displayLeft()+INSET, displayTop()+INSET, (displayWidth()-2*INSET)*fraction, displayHeight()-2*INSET, canvas); bar.setColor(Color.blue); } // Change the fraction of the display filled by the bar public void setFraction( double aFraction) { fraction = aFraction; positionContents(); } // Resize and reposition the bar appropriately protected void positionContents( ) { bar.moveTo( displayLeft()+INSET, displayTop()+INSET ); bar.setWidth( (displayWidth()-2*INSET)*fraction ); bar.setHeight( displayHeight()-2*INSET ); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?