So Id like to have 2 JPanels. Up JPanel (introPanel) and down JPanel (mainPanel). Id like to add keyListener to JFrame so when I press any key up panel hides so we can see down panel. How should the code look like to work?
class MainFrame extends JFrame {
private MainPanel mainPanel = new MainPanel();
private IntroPanel introPanel = new IntroPanel();
MainFrame() {
add(mainPanel);
add(introPanel);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent ev) {
introPanel.setVisible(false);
}
});
pack();
setVisible(true);
}
}
This code doesn't hide introPanel. What's wrong?