joker_joe
Cadet 1st Year
- Registriert
- Aug. 2013
- Beiträge
- 14
also ich bin gerade dabei ein kleines Spiel mit Java zu programmieren das über Netzwerk läuft.
Ich bin noch nicht so gut in Java darum brauch ich Hilfe.
Hier der Code:
das ist mein code und der Fehler dazu ist:
KeyEventClass is not abstract and does not override abstract method actionPerformer(ActionEvent) in ActionListener
Vielen Dank schon im Voraus !
Ich bin noch nicht so gut in Java darum brauch ich Hilfe.
Hier der Code:
Code:
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.Object;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.Timer;
import java.util.EventListener;
public class KeyEventClass extends JFrame implements ActionListener {
private int dx;
private int dy;
private Timer timer;
public KeyEventClass(){
this.setLayout(new BorderLayout());
JTextField field = new JTextField();
field.addActionListener(this);
this.add(field, BorderLayout.CENTER);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.timer = new Timer(1000, this);
this.timer.start();
this.Print();
}
public void keyTyped(KeyEvent e) {
// if(e.getKeyCode() == KeyEvent.VK_UNDEFINED){
//System.out.println("Kein Unicode-Character");
//}
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_SPACE) {
}
if (key == KeyEvent.VK_LEFT) {
dx = -1;
}
if (key == KeyEvent.VK_RIGHT) {
dx = 1;
}
if (key == KeyEvent.VK_UP) {
dy = -1;
}
if (key == KeyEvent.VK_DOWN) {
dy = 1;
}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = 0;
}
if (key == KeyEvent.VK_RIGHT) {
dx = 0;
}
if (key == KeyEvent.VK_UP) {
dy = 0;
}
if (key == KeyEvent.VK_DOWN) {
dy = 0;
}
}
public void Print() {
while (true) {
System.out.println( dx + dy);
}
}
public static void main(String[] args) {
new KeyEventClass();
}
}
KeyEventClass is not abstract and does not override abstract method actionPerformer(ActionEvent) in ActionListener
Vielen Dank schon im Voraus !