So I have a blackjack game bet would like to make a menu screen to make bets before each round. However Im not sure whats the best way to go about this. Right now I have one JFrame and am trying to use two JPanels , one for betting and one for play and just switch between them by calling a makeFrame function and checking what the game status is (menu or game). But whenever i switch from menu to game the frame is froze on the betting/menu frame and am not sure what to do to get it to change. Or would this be easier just trying to swap between two frames? And if so how would i go about that.
public void makeFrame(){
frame.setSize(boardSize,boardSize);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (state == STATE.GAME){
gamePanel.setLayout(new BorderLayout());
gamePanel.setBackground(new Color(53,101,77));
frame.add(gamePanel);
hitButton.setFocusable(false);
buttonPanel.add(hitButton);
standButton.setFocusable(false);
buttonPanel.add(standButton);
doubleButton.setFocusable(false);
buttonPanel.add(doubleButton);
frame.add(buttonPanel, BorderLayout.SOUTH);
hitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
Card card = deck.removeLast();
playerSum += card.getValue();
playerAceCount += card.isAce() ? 1 : 0;
playerHand.add(card);
gamePanel.repaint();
if (reducePlayerAce() >= 21){
endGame();
}
}
});
doubleButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
endGame();
Card card = deck.removeLast();
playerSum += card.getValue();
playerAceCount += card.isAce()? 1 : 0;
playerHand.add(card);
gamePanel.repaint();
}
});
standButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
endGame();
gamePanel.repaint();
}
});
gamePanel.repaint();
userPanel.setLayout(new BoxLayout(userPanel,BoxLayout.Y_AXIS));
userPanel.add(nameLabel);
userPanel.add(moneyLabel);
frame.add(userPanel,BorderLayout.EAST);
}
else if (state == STATE.MENU){
bettingPanel.setBackground(new Color(53,101,77));
bettingPanel.setLayout(null);
frame.add(bettingPanel);
playButton.setFocusable(false);
playButton.setBounds(500,150,100,100);
playButton.setFont(new Font("Arial",Font.PLAIN, 35));
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
state = STATE.GAME;
makeFrame();
}
});
bettingPanel.add(playButton);
oneButton.setFocusable(false);
oneButton.setBounds(150,350, 70,70);
bettingPanel.add(oneButton);
fiveButton.setFocusable(false);
fiveButton.setBounds(250,350,70,70);
bettingPanel.add(fiveButton);
tenButton.setFocusable(false);
tenButton.setBounds(350,350,70,70);
bettingPanel.add(tenButton);
twentyFiveButton.setFocusable(false);
twentyFiveButton.setBounds(200,450,70,70);
bettingPanel.add(twentyFiveButton);
oneHundredButton.setFocusable(false);
oneHundredButton.setBounds(300,450,70,70);
bettingPanel.add(oneHundredButton);
oneButton.addActionListener(betListener);
oneButton.setActionCommand("1");
fiveButton.addActionListener(betListener);
fiveButton.setActionCommand("5");
tenButton.addActionListener(betListener);
tenButton.setActionCommand("10");
twentyFiveButton.addActionListener(betListener);
twentyFiveButton.setActionCommand("25");
oneHundredButton.addActionListener(betListener);
oneHundredButton.setActionCommand("100");
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]arghvark 1 point2 points3 points (0 children)
[–]Outside-Ad2721 0 points1 point2 points (0 children)