Sorry for the late reply, was busy with exams.
I'm trying to get the g.drawLine to execute only when the mouse is clicked (not held down). In your code, when I ran it, the line still appears after releasing the mouse. I tried to use a boolean to find when it is held down but it does not work.
CODE
public class Test extends Applet implements Runnable, MouseListener, KeyListener{
boolean click=false;
int xrocket, yrocket;
int[] soldier = {250, 250, 4, 2};
public void mouseClicked(MouseEvent e) {
xrocket = e.getX();
yrocket = e.getY();
click=true;
repaint();
}
public void mouseReleased(MouseEvent e) {
click=false;
}
public void paint(Graphics g) {
if(click){
g.drawLine(soldier[0]+35, soldier[1]+15, xrocket, yrocket); //soldier array variables are controlled by user input
}
}
Thanks for the help Komer
This post has been edited by poomy: 29 May, 2009 - 12:30 AM