Was kann ich machen?
Java:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;
public class Tetris extends JApplet implements KeyListener{
private ImageIcon ball;
private JLabel balllabel;
private int xpos = 0;
private int ypos = 120;
public void init(){
setBackground(Color.black);
setLayout(null);
resize(500, 300);
this.addKeyListener(this);
ball = new ImageIcon("kickerslogo.png");
balllabel = new JLabel(ball);
balllabel.setVisible(true);
balllabel.setBounds(xpos,ypos,50,50);
add(balllabel);
setFocusable(true);
requestFocus();
}
public void keyPressed(KeyEvent k) {
}
public void keyReleased(KeyEvent k) {
}
public void keyTyped(KeyEvent k) {
if (k.getKeyChar() == 'w') {
ypos-=20;
balllabel.setBounds(xpos,ypos,50,50);
}
else if (k.getKeyChar() == 's') {
ypos+=20;
balllabel.setBounds(xpos,ypos,50,50);
}
else if (k.getKeyChar() == 'd') {
xpos+=20;
balllabel.setBounds(xpos,ypos,50,50);
}
else if (k.getKeyChar() == 'a') {
xpos-=20;
balllabel.setBounds(xpos,ypos,50,50);
}
}
}