Java programmierung Fehler

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Java programmierung Fehler

    Wie kann ich das Problem beheben ?

    Fehlermeldung: KeyHandler cannot be resolved to a type

    Code:

    Quellcode

    1. package game;
    2. import java.awt.Color;
    3. import java.awt.Graphics;
    4. import java.awt.event.KeyEvent;
    5. import java.awt.event.KeyListener;
    6. import javax.swing.JFrame;
    7. import javax.swing.JLabel;
    8. public class Frame extends JFrame {
    9. Background bg = new Background();
    10. private Screen screen;
    11. final Player player;
    12. private boolean player_up = false ;
    13. private boolean player_down = false;
    14. private boolean player_right = false;
    15. private boolean player_left = false;
    16. public Frame(Player player, Background bg){
    17. super ("Spiel");
    18. screen = new Screen();
    19. screen.setBounds(0,0, 800, 600);
    20. add(screen);
    21. addKeyListener(new KeyHandler()); // Hier ist der Fehler
    22. this.bg = bg;
    23. this.player = player;
    24. }
    25. public boolean getUp(){
    26. return player_up;
    27. }
    28. public boolean getDown(){
    29. return player_down;
    30. }
    31. public boolean getLeft(){
    32. return player_left;
    33. }
    34. public boolean getRight(){
    35. return player_right;
    36. }
    37. private class Screen extends JLabel{
    38. protected void paintComponent(Graphics g){
    39. super.paintComponent(g);
    40. g.drawImage(bg.getLook(), 0, 0, null);
    41. g.drawImage(player.getLook(), player.getbounding().y, player.getbounding().x, null);
    42. }
    43. public class KeyHandler implements KeyListener{
    44. @Override
    45. public void keyPressed(KeyEvent e) {
    46. if(e.getKeyCode()== KeyEvent.VK_W)
    47. player_up = true;
    48. if(e.getKeyCode()== KeyEvent.VK_S)
    49. player_down = true;
    50. if(e.getKeyCode() == KeyEvent.VK_A)
    51. player_left = true;
    52. if(e.getKeyCode()== KeyEvent.VK_D)
    53. player_right = true;
    54. }
    55. @Override
    56. public void keyReleased(KeyEvent e) {
    57. if(e.getKeyCode()== KeyEvent.VK_W)
    58. player_up = false;
    59. if(e.getKeyCode()== KeyEvent.VK_S)
    60. player_down = false;
    61. if(e.getKeyCode() == KeyEvent.VK_A)
    62. player_left = false;
    63. if(e.getKeyCode()== KeyEvent.VK_D)
    64. player_right = false;
    65. }
    66. @Override
    67. public void keyTyped(KeyEvent e) {
    68. // TODO Auto-generated method stub
    69. }
    70. }
    71. }
    72. }
    Alles anzeigen