Example usage for javax.swing JPanel removeKeyListener

List of usage examples for javax.swing JPanel removeKeyListener

Introduction

In this page you can find the example usage for javax.swing JPanel removeKeyListener.

Prototype

public synchronized void removeKeyListener(KeyListener l) 

Source Link

Document

Removes the specified key listener so that it no longer receives key events from this component.

Usage

From source file:com.net2plan.gui.GUINet2Plan.java

private static JPanel showAbout() {
    final JPanel aboutPanel = new JPanel();

    ImageIcon image = new ImageIcon(
            ImageUtils.readImageFromURL(GUINet2Plan.class.getResource("/resources/gui/logo.png")));
    JLabel label = new JLabel("", image, JLabel.CENTER);

    aboutPanel.setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow][grow]"));
    aboutPanel.add(label, "alignx center, aligny bottom, wrap");
    aboutPanel.add(new JLabel(ABOUT_TEXT), "alignx center, aligny top");
    aboutPanel.setFocusable(true);/*from  w ww  . j av  a 2  s . co m*/
    aboutPanel.requestFocusInWindow();

    aboutPanel.addKeyListener(new KeyAdapter() {
        private final int[] sequence = new int[] { KeyEvent.VK_UP, KeyEvent.VK_UP, KeyEvent.VK_DOWN,
                KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
                KeyEvent.VK_A, KeyEvent.VK_B };
        private int currentButton = 0;

        @Override
        public void keyPressed(KeyEvent e) {
            int keyPressed = e.getKeyCode();

            if (keyPressed == sequence[currentButton]) {
                currentButton++;

                if (currentButton == sequence.length) {
                    ErrorHandling.setDebug(true);
                    aboutPanel.removeKeyListener(this);
                }
            } else {
                currentButton = 0;
            }
        }
    });

    return aboutPanel;
}