这是我在Java中的小小垄断的代码。 当我使用新的Monopoly()运行我的测试程序时;正如你所看到的,我在垄断,游戏中的圆形游戏中创造了测试,棋盘和游戏的垄断。我想将我的令牌添加到董事会。但是,我看不到令牌。我找不到问题任何人都可以帮助我吗? (我甚至尝试过调试)
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Board extends JPanel {
private ImageIcon image;
private JLabel label;
public Board() {
image = new ImageIcon("board.jpg");
setLayout(null);
label = new JLabel(new ImageIcon("board.jpg"));
label.setSize(700, 700);
add(label);
}
}
public class Game {
Player p1;
Player p2;
public Game(Board b) {
p1 = new Player("Onurcan", 1);
p2 = new Player("Baturay", 2);
Round r = new Round(p1, b);
}
public Player getP1() {
return p1;
}
public Player getP2() {
return p2;
}
}
public class Monopoly {
public Monopoly() {
JFrame frame = new JFrame("Monopoly");
Board b = new Board();
Game g = new Game(b);
frame.setSize(1378, 900);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(b);
frame.setVisible(true);
}
}
public class Round {
private static final int unitChange = 50;
int posx1 = 650;
int posy1 = 650;
public Round(Player p, Board b) {
Dice d = new Dice();
p.setPosition((p.getPosition() + d.getDice()));
if (p.getPosition() >= 40) {
p.setPosition(p.getPosition() - 40);
}
changePosition(p, d, b);
}
public void changePosition(Player p, Dice d, Board b) {
p.getToken().setSize(25,25);
p.getToken().setLocation(posx1, posy1);
b.add(p.getToken());
}
public class Player {
String pname;
int balance;
int pnumber;
int position;
JPanel token;
public Player(String name, int pnumber) {
pname = name;
balance = 1500;
position = 0;
token = new Token(pnumber);
}
public JPanel getToken() {
return token;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}