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

📄 stillpatheticpong.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;// plays a slightly more advanced version of pong where the ball// can bounce off of the paddlepublic class StillPatheticPong extends WindowController{        // Margin between court and window boundaries    private static final int        COURT_MARGIN = 50;        // dimensions of the paddle    private static final int        PADDLE_WIDTH = 50,        PADDLE_HEIGHT = 20;    FilledRect paddle;    FramedRect boundary;        // the boundary of the playing area.        public void begin()    {        // make the playing area        boundary = new FramedRect(COURT_MARGIN, COURT_MARGIN,                                  canvas.getWidth() - 2*COURT_MARGIN,                                  canvas.getHeight() - 2*COURT_MARGIN,                                  canvas);                // make the paddle        paddle =            new FilledRect((canvas.getWidth()-PADDLE_WIDTH)/2,                           boundary.getY() + boundary.getHeight() - PADDLE_HEIGHT -1,                           PADDLE_WIDTH, PADDLE_HEIGHT,                           canvas);    }        public void onMouseClick(Location point)    {        // make a new ball when the player clicks        new BouncingBall(boundary.getX() + boundary.getWidth()/2,                         boundary.getY(),                          paddle,                         canvas).start();    }        public void onMouseMove(Location point)    {        if ( point.getX() < boundary.getX() )            {                // place paddle at left edge of the court                paddle.moveTo( boundary.getX(),                               paddle.getY() );            }        else if ( point.getX() > boundary.getX() + boundary.getWidth() - PADDLE_WIDTH)            {                // place paddle at right edge of the court                paddle.moveTo( boundary.getX() + boundary.getWidth() - PADDLE_WIDTH,                               paddle.getY());            }        else            {                // keep the edge of the paddle lined up with the mouse                paddle.moveTo( point.getX(),                               paddle.getY());            }    }    }

⌨️ 快捷键说明

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