sillybasketball.java

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

JAVA
40
字号
import objectdraw.*;// program that displays how many times the mouse has been clickedpublic class SillyBasketBall extends WindowController{        // the Text object which displays the count        private Text display;        // the oval that represent the hoop        private FramedOval hoop;        // the number of points        private int score;        // initialize the counter and the text message        public void begin()        {                score = 0;                                display = new Text("Take a shot.",                                                        0, 350, canvas);                display.setFontSize(16);                display.move( (canvas.getWidth()-display.getWidth())/2, 0 );                                hoop = new FramedOval( (canvas.getWidth()-100)/2, 50,                                                                100, 60,                                                                 canvas);        }        // increment the counter and update the text if player scores        public void onMouseRelease(Location point)        {                score = score + 2;                display.setText("You have scored " + score + " points.");                display.moveTo( (canvas.getWidth()-display.getWidth())/2, 350 );        }}

⌨️ 快捷键说明

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