我希望 money1
按钮位于 Jlabel
下方,上面写着 fillmeup
但当我尝试添加按钮时,它会转到标签不在其下方。我正在使用小程序并使用 JButtons
。任何建议将不胜感激。
The blackJack game I am trying to make
setBackground( new Color(130,50,40) );
setLayout( new BorderLayout(3,3) );
BlackjackCanvas board = new BlackjackCanvas();
add(board, BorderLayout.CENTER);
Panel buttonPanel = new Panel();
buttonPanel.setBackground(new Color(220,200,180));
add(buttonPanel, BorderLayout.SOUTH);
Panel buttonPane2 = new Panel();
buttonPane2.setBackground(new Color(220,200,180));
add(buttonPane2, BorderLayout.EAST);
Panel buttonPane3 = new Panel();
buttonPane3.setBackground(new Color(220,200,180));
add(buttonPane3, BorderLayout.WEST);
Button hit = new Button( "Hit!" );
hit.addActionListener(board);
hit.setBackground(Color.lightGray);
buttonPanel.add(hit);
Button stand = new Button( "Stand!" );
stand.addActionListener(board);
stand.setBackground(Color.lightGray);
buttonPanel.add(stand);
Button newGame = new Button( "New Game" );
newGame.addActionListener(board);
newGame.setBackground(Color.lightGray);
buttonPanel.add(newGame);
JLabel money = new JLabel( "Fill me up!" );
money.setBackground(Color.lightGray);
buttonPane2.add(money);
Button money1 = new Button( "A rare commodity" );
newGame.addActionListener(board);
newGame.setBackground(Color.lightGray);
buttonPane2.add(money1);
最佳答案
我会考虑引用这里的文档 Java Layout Options
并将 ButtonPane2 布局管理器设置为满足您需求的布局管理器。
这可以使用 setLayout(new xxxLayout());
关于java - 按钮放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44098425/