java随即跳动的小球求助。。。
在JAVA实现跳动的小球。。代码如下:package cn;
import java.awt.Graphics;
import java.awt.*;
import javax.swing.JPanel;
public class BallOnPanel extends JPanel implements Runnable{
int x=110;
int y=110;
public void paint(Graphics g){
super.paint(g);
g.fillOval(x, y, 30, 30);
}
public void run() {
while(true){
x=(int)(Math.random()*450);
y=(int)(Math.random()*350);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
this.repaint();
}
}
}
2:
package cn;
import javax.swing.JFrame;
public class BallTest {
JFrame jframe=null;
BallOnPanel ball=null;
public BallTest(){
jframe=new JFrame();
ball=new BallOnPanel();
ball.setSize(450,350);
jframe.setSize(500, 400);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.add(ball);
new Thread(ball).start();
}
public static void main(String[] args) {
BallTest bt=new BallTest();
}
}
请问怎么利用MouseListener。让我鼠标点击到小球,小球就变大,速度变快。。