Hi thanks for your quick answear.
I might aswell say that I have an ActionPerformed but for now it might aswell just be a
System.out.println("test");
that says if the button actually does something.
The player class atm looks like this.
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class Player {
public static ImageIcon image;
public static ImageIcon fire = new ImageIcon("pieces/brook.png");
public ImageIcon wizard = new ImageIcon("pieces/bking.png");
public static int currentRow;
public static int currentCol;
public Player(String str, int player) throws SpriteException {
if(player == 1){
currentRow = 5;
currentCol = 0;
}
if(player == 2){
currentRow = 0;
currentCol = 0;
}
}
public void moveLeft(){
grid[Player.currentRow][Player.currentCol].setIcon(null);
grid[Player.currentRow][Player.currentCol+1].setIcon(player1.getPic());
}
public void setImage(String str){
if(str.equals("Wizard")){
image = wizard;
}
if(str.equals("Fire")){
image = fire;
}
}
public static ImageIcon getPic(){
ImageIcon p = image;
return p;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
moveLeft();
}
}
}
I havent really been doing the movement yet. I just want the keyEvent to work. Since now i dont even get a system.out.print if i put on for Space. It just gives me alot of Nullpointerexceptions etc.
Thanks.