External Exam Download Resources Web Applications Games Recycle Bin

dragster



setup Form
dragster jFrame Form
set Label Mouse Click Event
add mouse click event
import Packages
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.Timer;

public Variables
public Timer animateCar = null;
public Point carLocation = null;

jFrame Constructor
ActionListener movePixels = (ActionEvent meh) -> {
	carLocation = lblCar.getLocation();
	int x = (int)carLocation.getX();
	int y = (int)carLocation.getY();
	lblCar.setLocation(x+1, y);
	if(x>100){ 
		animateCar.stop();
		JOptionPane.showMessageDialog(null, "winner");
	}
};
animateCar = new Timer(10, movePixels);

lblGo (mouseClicked)
animateCar.start();