fork download
  1. /**
  2.  * キー押しっぱなしなのにkeyReleasedが呼ばれる問題
  3.  *
  4.  * {} <- こうなってほしい
  5.  * {{{{{{{{{} <- ぐぐった所こうなるのが正常らしい
  6.  * {}{}{}{}{}{}{}{}{}{}{}{}{}{}{} <- なぜかこうなる
  7.  * */
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11.  
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.KeyListener;
  14.  
  15. public class Main extends JFrame {
  16. public Main() {
  17. JPanel panel = new KLPanel();
  18. getContentPane().add(panel);
  19. }
  20.  
  21. public static void main(String[] args) {
  22. Main frame = new Main();
  23. frame.setVisible(true);
  24. }
  25. }
  26.  
  27. class KLPanel extends JPanel implements KeyListener {
  28. public KLPanel() {
  29. setFocusable(true);
  30. addKeyListener(this);
  31. }
  32. public void keyPressed(KeyEvent e) {
  33. System.out.print("{" /*+e.getKeyCode()*/ );
  34. }
  35. public void keyReleased(KeyEvent e) {
  36. System.out.print( /*" "+e.getKeyCode()+*/ "}");
  37. }
  38. public void keyTyped(KeyEvent e) {}
  39. }
  40.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9: error: ‘import’ does not name a type
prog.cpp:10: error: ‘import’ does not name a type
prog.cpp:12: error: ‘import’ does not name a type
prog.cpp:13: error: ‘import’ does not name a type
prog.cpp:15: error: expected unqualified-id before ‘public’
stdout
Standard output is empty