fork download
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Sample7 extends JApplet
  6. {
  7. private JLabel lb1, lb2;
  8.  
  9. public void init()
  10. {
  11. lb1 = new JLabel("矢印キーで選びなさい");
  12. lb2 = new JLabel();
  13.  
  14. add(lb1, BorderLayout.NORTH);
  15. add(lb2, BorderLayout.SOUTH);
  16.  
  17. addKeyListener(new SampleKeyListener());
  18. }
  19.  
  20. class SampleKeyListener extends KeyAdapter
  21. {
  22. @Override
  23. public void keyPressed(KeyEvent e)
  24. {
  25. String str;
  26. int k = e.getKeyCode();
  27. switch(k){
  28. case KeyEvent.VK_UP:
  29. str = "上"; break;
  30. case KeyEvent.VK_DOWN:
  31. str = "下"; break;
  32. case KeyEvent.VK_LEFT:
  33. str = "左"; break;
  34. case KeyEvent.VK_RIGHT:
  35. str = "右"; break;
  36. default:
  37. str = "他のキー";
  38. }
  39. lb2.setText(str + "ですね");
  40. }
  41. }
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class Sample7 is public, should be declared in a file named Sample7.java
public class Sample7 extends JApplet
       ^
1 error
stdout
Standard output is empty