Question: Looking for some help on an assignment. I managed to get some of the GUI done for the slot machine but have no clue on
Looking for some help on an assignment. I managed to get some of the GUI done for the slot machine but have no clue on where to start to get most of the game running. any help would be great.


import javax.swing.*;
import java.awt.*;
import java.util.Random;
class InfoPanel extends JPanel {
public InfoPanel() {
setPreferredSize(new Dimension(500,100));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("Balance",50,50);
}
}
class ColorPanel extends JPanel {
private Color col;
public ColorPanel() {
Random rnd = new Random();
int colorCode = rnd.nextInt(3);
if (colorCode == 0) {
col = Color.RED;
} else if (colorCode == 1) {
col = Color.GREEN;
} else {
col = Color.BLUE;
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(col);
g.fillOval(20,20,100,100);
g.fillRect(20,20,100,100);
}
}
class MyFrame extends JFrame {
public MyFrame() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100,100,500,500);
setTitle("Java Slot Machine");
Container c = getContentPane();
c.setLayout(new BorderLayout());
JPanel panSouth = new JPanel();
JButton btnMAX = new JButton("Bet Max");
panSouth.add(btnMAX);
JButton btnMIN = new JButton("Bet Min");
panSouth.add(btnMIN);
JButton btnSPIN = new JButton("Spin");
panSouth.add(btnSPIN);
c.add(panSouth,BorderLayout.SOUTH);
InfoPanel panInfo = new InfoPanel();
c.add(panInfo,BorderLayout.NORTH);
JPanel panCenter = new JPanel();
panCenter.setLayout(new GridLayout(1,3));
ColorPanel cpLeft = new ColorPanel();
ColorPanel cpMid = new ColorPanel();
ColorPanel cpRight = new ColorPanel();
panCenter.add(cpLeft);
panCenter.add(cpMid);
panCenter.add(cpRight);
c.add(panCenter,BorderLayout.CENTER);
}
}
public class ClarkslotMachine {
public static void main(String[] args) {
MyFrame frm = new MyFrame();
frm.setVisible(true);
}
}
In this assignment, you will create a slot machine app. The user interface will look like this: JSlotMachine Version 1.0 Welcome to JSlotMachine 1.0 Bet Max Bet Min Spin The player starts with a balance of $1.00. If they press "Spin", they bet $0.25. If they press "Bet Max", they wager $0.50. If they press Bet Min", they wager $0.10. When they press one of these buttons, the arrangement of tiles will randomly change. Each tile will display a red, green, or blue circle or rectangle. When all three tiles show the same shape and color, the player wins what they bet. If the three tiles do not show the same shape and color, the player loses what they bet. The program ends when the player runs out of money For example, let's suppose that the player first presses "Spin". This is how the display might Look after that first play JSlotMachine Version 1.0 Current balance: $0.75 Bet Max et Min Spi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
