jeudi 1 janvier 2015

Calling a method as a variable

I have what I think is a simple question but I cannot find the answer. I simply want to use the value returned by a method in an if else statement. I don't want to call the method in the body of the if statement, I want the method to be used in the comparison. My goal is to be able to control a box on the screen but currently I am just trying to test if my arrow key methods work. Thanks for any help!



package robot;
import java.awt.*;
import java.awt.event.KeyEvent;

public class Robot {
public static void main(String[] args) {
if (keyPressedLeft==true) {
System.out.println("You pressed the left arrow");
}
}
public boolean keyPressedLeft(KeyEvent e){
if (e.getKeyCode()== KeyEvent.VK_LEFT) {
return true;
} else {
return false;
}
}

Aucun commentaire:

Enregistrer un commentaire