Wie kann ich das Problem beheben ?
Fehlermeldung: KeyHandler cannot be resolved to a type
Code:
Alles anzeigen
Fehlermeldung: KeyHandler cannot be resolved to a type
Code:
Quellcode
- package game;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Frame extends JFrame {
- Background bg = new Background();
- private Screen screen;
- final Player player;
- private boolean player_up = false ;
- private boolean player_down = false;
- private boolean player_right = false;
- private boolean player_left = false;
- public Frame(Player player, Background bg){
- super ("Spiel");
- screen = new Screen();
- screen.setBounds(0,0, 800, 600);
- add(screen);
- addKeyListener(new KeyHandler()); // Hier ist der Fehler
- this.bg = bg;
- this.player = player;
- }
- public boolean getUp(){
- return player_up;
- }
- public boolean getDown(){
- return player_down;
- }
- public boolean getLeft(){
- return player_left;
- }
- public boolean getRight(){
- return player_right;
- }
- private class Screen extends JLabel{
- protected void paintComponent(Graphics g){
- super.paintComponent(g);
- g.drawImage(bg.getLook(), 0, 0, null);
- g.drawImage(player.getLook(), player.getbounding().y, player.getbounding().x, null);
- }
- public class KeyHandler implements KeyListener{
- @Override
- public void keyPressed(KeyEvent e) {
- if(e.getKeyCode()== KeyEvent.VK_W)
- player_up = true;
- if(e.getKeyCode()== KeyEvent.VK_S)
- player_down = true;
- if(e.getKeyCode() == KeyEvent.VK_A)
- player_left = true;
- if(e.getKeyCode()== KeyEvent.VK_D)
- player_right = true;
- }
- @Override
- public void keyReleased(KeyEvent e) {
- if(e.getKeyCode()== KeyEvent.VK_W)
- player_up = false;
- if(e.getKeyCode()== KeyEvent.VK_S)
- player_down = false;
- if(e.getKeyCode() == KeyEvent.VK_A)
- player_left = false;
- if(e.getKeyCode()== KeyEvent.VK_D)
- player_right = false;
- }
- @Override
- public void keyTyped(KeyEvent e) {
- // TODO Auto-generated method stub
- }
- }
- }
- }