I've been staring at this for days...
I think the Imageicon
part is correct, and is referencing the right object.
It has something to do with creating the board, map, and stuff, and I'm not really good with that.
public class Maze {
public static final int SCREEN_SIZE = 1024;
public static void main(String[] args){
new Maze();
}
// help from: http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
public Maze(){
JFrame f = new JFrame();
f.setTitle("Maze");
f.add(new Board());
f.setSize(SCREEN_SIZE,SCREEN_SIZE);
f.setLocationRelativeTo(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
So you create the screen, make the board, get the images, and then paint depending on the contents of the array.
public class Board extends JPanel implements ActionListener {
public static final int TILE_SIZE = 32;
private Timer timer;
public Map m;
public Board(){
m = new Map();
timer = new Timer(25, this);
timer.start();
}
@Override
public void actionPerformed(ActionEvent e) {
repaint(); // TODO Auto-generated method stub
}
public void paint(Graphics g){
super.paint(g);
for (int y = 0; y < TILE_SIZE; y++) {
for (int x = 0; x < TILE_SIZE; x++) {
if(m.Map[x][y] == 0) {
g.drawImage(m.getFloor(), x * 32, y * 32, null);
}
if (m.Map[x][y] == 1) {
g.drawImage(m.getWall(), x * 32, y * 32, null);
}
}
}
}
}
public class Map {
public static Image floor, wall;
public int Map[][] = new int[Maze.SCREEN_SIZE / Board.TILE_SIZE][Maze.SCREEN_SIZE / Board.TILE_SIZE];
public Map() {
ImageIcon img = new ImageIcon("C://Users/Brian2/Pictures/backgrounds/FLOOR.png");
floor = img.getImage();
img = new ImageIcon("C://Users/Brian2/Pictures/backgrounds/WALL");
wall = img.getImage();
GenMap();
}
public void GenMap() {
for(int i = 0; i < Maze.SCREEN_SIZE / Board.TILE_SIZE; i++){
for(int j = 0; j < Maze.SCREEN_SIZE / Board.TILE_SIZE; j++){
Map[i][j] = 1;
}
}
}
public Image getWall() {
return wall;
}
public Image getFloor() {
return floor;
}
public void printMap() {}
}
It won't show anything on the JPanel
that opens when I run it. I don't know what's wrong. There are no errors and I've been stuck for about 4 days.