I am making something in java that when the F1 key is hit a JDialog window to apear.My current code:
public class Keyboard implements KeyListener {
private boolean[] keys = new boolean[120];
public boolean up, down, left, right, assets;
public void tick() {
assets = keys[KeyEvent.VK_F1];
}
public void keyPressed(KeyEvent e) {
keys[e.getKeyCode()] = true;
}
public void keyReleased(KeyEvent e) {
keys[e.getKeyCode()] = false;
}
public void keyTyped(KeyEvent e) {
}
}
And in my main class under the tick() method:
keyboard.tick();
if(keyboard.assets) ac.run();
The keyboard variable refers to the keyboard class while the ac variable refers to this class:
public class AssetsChooser extends JDialog {
JFileChooser fc = new JFileChooser();
public void run() {
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
add(fc);
System.out.println("It works.");
}
}
When I run my game and hit F1 no JDialog window appears nor does the Console display the method.