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

📄 betterbasketball.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;// This program awards points whenever the mouse is clicked// inside of the basket.public class BetterBasketBall extends WindowController{        // dimensions and locations for the hoop        private static final int HOOP_TOP = 50;        private static final int HOOP_HEIGHT = 60;        private static final int HOOP_WIDTH = 100;                // dimensions and locations for the score display        private static final int DISPLAY_FONT_SIZE = 16;        private static final int DISPLAY_TOP = 350;                // 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 = 0;        // initialize the counter and the text message        public void begin()        {                                display = new Text("Take a shot.",                                                        0, DISPLAY_TOP, canvas);                display.setFontSize(DISPLAY_FONT_SIZE);                display.move( (canvas.getWidth()-display.getWidth())/2, 0 );                                hoop = new FramedOval( (canvas.getWidth()-HOOP_WIDTH)/2, HOOP_TOP,                                                                HOOP_WIDTH, HOOP_HEIGHT,                                                                 canvas);                        }        // increment the counter if player scores and update the text        // appropriately        public void onMouseRelease(Location point)        {                if (hoop.contains(point)) {                                                score = score + 2;                        display.setText("You have scored " + score + " points.");                                        } else {                                                display.setText("WHOOPS!  You Missed.");                }                                display.moveTo( (canvas.getWidth() - display.getWidth()) / 2,                                                DISPLAY_TOP);        }}

⌨️ 快捷键说明

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