I am developing a project about time of countries. I want the main class to end while constantly showing the time when I press Ctrl+X. I used JFrame. When I press on just one key, the program is terminated. But I can't solve this using two keys. I tried some solutions found here. KeyPressed code and main class are below. This way the program doesn't stop.
Key Code:
public void keyPressed(KeyEvent e) {
System.out.println("Key Pressed " + KeyEvent.getKeyText(e.getKeyCode()) );
if("Right".equals(KeyEvent.getKeyText(e.getKeyCode())))
System.out.println("Right Button Detected");
if(e.getKeyCode()==KeyEvent.VK_CONTROL && e.getKeyCode()==KeyEvent.VK_X);
System.exit(0);
}
Main Code:
public class Main {
public static void main(String[] args) {
System.out.println("You enter CTRL X to exit the program.");
MyKeyListener klavye = new MyKeyListener();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addKeyListener(klavye);
frame.setVisible(true);
}