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

📄 ball.java~2~

📁 JAVA编写的BounceTest程序 供编程爱好者学习参考之用
💻 JAVA~2~
字号:
package bouncetest;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Ball extends Thread {  public Ball(JPanel b, Color c) { box = b; color = c; }     public void draw()     {  Graphics g = box.getGraphics();        g.setColor(color);        g.fillOval(x, y, XSIZE, YSIZE);        g.dispose();     }     public void move()     {  if (!box.isVisible()) return;        Graphics g = box.getGraphics();        g.setXORMode(box.getBackground());        g.setColor(color);        g.fillOval(x, y, XSIZE, YSIZE);        x += dx;        y += dy;        Dimension d = box.getSize();        if (x < 0)        { x = 0; dx = -dx; }        if (x + XSIZE >= d.width)        { x = d.width - XSIZE; dx = -dx; }        if (y < 0)        { y = 0; dy = -dy; }        if (y + YSIZE >= d.height)        { y = d.height - YSIZE; dy = -dy; }        g.fillOval(x, y, XSIZE, YSIZE);        g.dispose();     }     public void run()     {  try        {  draw();           for (int i = 1; i <= 1000; i++)           {  move();              sleep(5);           }        }        catch(InterruptedException e) {}     }     private JPanel box;     private static final int XSIZE = 10;     private static final int YSIZE = 10;     private int x = 0;     private int y = 0;     private int dx = 2;     private int dy = 2;     private Color color;}

⌨️ 快捷键说明

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