public enum Direction {
UP(KeyEvent.VK_UP), DOWN(KeyEvent.VK_DOWN), LEFT(KeyEvent.VK_LEFT), RIGHT(KeyEvent.VK_RIGHT);
public final int vk;
// constructor
Direction(int vk) {
this.vk = vk;
}
// Direction : type
// fromVK : name
public static Direction fromVK(int vk) {
for (Direction d : values()) {
if (d.vk == vk) {
return d;
}
}
return null;
}
}
Why can we use values()? And the enum here is each of them has its own sequence of numbers, so Direction(int vk) can take int
0 Answer
No answer yet
这家伙很懒,什么都没留下...