little help please - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

little help please

nabighnabigh Posts: 9Member
hi guys
I am trying to make a java program that whenever I make mouse click,a ball is drawn and goes up until it vanishes (goes out of range)
so far I was able to make the ball goes up,but I couldn't do it within the mouseclicked method

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.applet.*;
public class circle extends Applet implements Runnable,MouseListener{
Graphics g;
Rectangle r=new Rectangle(0,0,getWidth(),getHeight());
int x=500;
int y=500;
public void start(){
Thread t=new Thread(this);
t.start();
}
public circle(){

addMouseListener(this);
}

public void paint(Graphics g){
g.setColor(Color.GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.WHITE);
g.drawOval(x, y, 50, 50);
}


public void run() {
int dx=0, dy=20;
while (true) {
for(int i=0; i<5; i++) {
if (false)
return;
x-=dx;
y-=dy;
repaint();
try {
Thread.sleep(150);
}catch(InterruptedException e) {
e.printStackTrace();
}
}

}
}

public void drawCircle(int x, int y) {
Graphics g = this.getGraphics();
g.drawOval(x, y, x, y);

g.fillOval(x, y, 2, 2);
}
public void mouseClicked(MouseEvent e) {
if (r.contains(e.getX(), e.getY())){
g.drawOval(0,0, 50, 50);
repaint();
}

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}
}



please help
Sign In or Register to comment.