I am trying to build a small monopoly game. Here you can see the part of the code that I am having trouble with.
public class Board extends JPanel {
private ImageIcon image;
private JLabel label;
static Player p1;
static Player p2;
public Board() {
p1 = new Player("Jack", 1);
p2 = new Player("Matt", 2);
setLayout(null);
image = new ImageIcon("board.jpg");
label = new JLabel(new ImageIcon("/Users/Onurcan/Documents/"
+ "workspace/Monopoly/src/board.jpg"));
add(p1.getToken());
add(label);
}
public class Monopoly {
public Monopoly() {
JFrame frame = new JFrame("Monopoly");
frame.setSize(1378, 900);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Board(), BorderLayout.WEST);
frame.setVisible(true);
}
}
As you can guess I create a new Monopoly object in my test class to run this program. When I remove the setLayout(null) I can see both token and board in program. But without typing setLayout(null) I cannot move my token to starting point. While creating player if second parameter is 1 that means token is a hat, if second parameter is 2 it means it is a shoe. So I am asking that how can I do not lose visual with setLayout(null)? Or withouy setting layout to null how can I change my tokens position?