Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.