Written by Danielle Kain, Kevin Miller
addMouseListeners();
addKeyListeners();
public void mouseClicked(MouseEvent e) {
//this method is called when the mouse is clicked
}
public void mouseMoved(MouseEvent e) {
//this method is called when the mouse is moved
}
public void keyPressed(KeyEvent e) {
//this method is called when any key is pressed
}
waitForClick(); //this will pause until the user clicks
Here are some examples of how to use events:
public void mouseClicked(MouseEvent e) {
System.out.println("x: " + e.getX() + " y: " + e.getY());
//This will print out the coordinates of where you click
}
public void keyPressed(KeyEvent e) {
System.out.println("key pressed: " + e.getKey());
//This will print out which key was pressed
}