public class Game {
JFrame jFrame=new JFrame();
Dice dice1=new Dice();
Dice dice2=new Dice();
Dice dice3=new Dice();
Box BigOrSmallBox = Box.createVerticalBox();
Label label=new Label("请按下大或小按钮");
JPanel BigOrSmallSelect=new JPanel();
JPanel BigOrSmallPanel=new JPanel();
JButton big=new JButton();
JButton small=new JButton();
// JPanel BigOrSmallSelect=new JPanel();
int bigType=0;
int smallType=0;
JPanel dicePanel1=new JPanel();
JPanel dicePanel2=new JPanel();
JPanel dicePanel3=new JPanel();
DiceCanvas drawDice1=new DiceCanvas();
DiceCanvas drawDice2=new DiceCanvas();
DiceCanvas drawDice3=new DiceCanvas();
BigPaint drawBig=new BigPaint();
SmallPaint drawSmall=new SmallPaint();
public void init(){
jFrame.setBounds(300,300,1625,875);
jFrame.setLayout(null);
jFrame.setResizable(false);
BigOrSmallPanel.setLayout(null);
BigOrSmallSelect.setLayout(null);
BigOrSmallPanel.setBounds(50,50,750,210);
BigOrSmallPanel.setBackground(new Color(215,228,239));
label.setFont(new Font(Font.SERIF, Font.PLAIN, 24));
label.setBounds(270,0,750,50);
BigOrSmallSelect.setBounds(0,50,750,160);
BigOrSmallSelect.setBorder(new LineBorder(Color.gray,1));
BigOrSmallSelect.setBackground(new Color(215,228,239));
big.setBounds(80,20,200,125);
small.setBounds(450,20,200,125);
BigOrSmallSelect.add(big);
BigOrSmallSelect.add(small);
BigOrSmallPanel.add(label);
BigOrSmallPanel.add(BigOrSmallSelect);
big.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawDice1.repaint();
drawDice2.repaint();
drawDice3.repaint();
}
});
small.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawDice1.repaint();
drawDice2.repaint();
drawDice3.repaint();
}
});
big.add(drawBig);
small.add(drawSmall);
dicePanel1.setLayout(null);
dicePanel2.setLayout(null);
dicePanel3.setLayout(null);
drawDice1.setDice(dice1);
drawDice2.setDice(dice2);
drawDice3.setDice(dice3);
drawDice1.setBounds(40,40,80,80);
drawDice2.setBounds(40,40,80,80);
drawDice3.setBounds(40,40,80,80);
dicePanel1.add(drawDice1);
dicePanel2.add(drawDice2);
dicePanel3.add(drawDice3);
dicePanel1.setBounds(160,345,160,160);
dicePanel2.setBounds(320,345,160,160);
dicePanel3.setBounds(480,345,160,160);
dicePanel1.setBorder(new LineBorder(Color.gray,1));
dicePanel2.setBorder(new LineBorder(Color.gray,1));
dicePanel3.setBorder(new LineBorder(Color.gray,1));
jFrame.add(dicePanel1);
jFrame.add(dicePanel2);
jFrame.add(dicePanel3);
jFrame.add(BigOrSmallPanel);
jFrame.setVisible(true);
}
应该是坐标设置的问题,修改一下坐标试试。