Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:09:30+00:00 2026-05-26T00:09:30+00:00

I am trying to create a slot machine in java. In this slot machine

  • 0

I am trying to create a slot machine in java. In this slot machine I have completed the basic beginning of the project. I have the animators that lands on a random space (cherry, blank, seven, etc), the background, buttons to start and bet in the opening, however I have to figure out the ending of the slot; how to make the results of the slot machine appear without the user clicking a button. To do this I figure the best way is to dive into the realm of threads. However when I tried to create a simple thread, the animators stopped working and when I took the thread out, the animators did work. It is quite the conundrum.
Here is some of the code if that helps explanation :

public class SlotMachineOpeningGraphic extends JPanel implements Runnable
{
    JLayeredPane layeredPane= new JLayeredPane ();
JFrame frame = new JFrame();

public Thread thread;
public volatile boolean running = false;

Player plyr = new Player ();

public static final long startTime = System.currentTimeMillis ();

JLabel numberBet = new JLabel ("" + plyr.getBet()); //things that change on JFrame
JLabel numberAccount = new JLabel (""+ plyr.getAccount ());
JButton betButton = new JButton ("Bet ++");
JButton playAgain = new JButton ("Start");

public SlotMachineOpeningGraphic()   
 {
    layeredPane.setPreferredSize(new Dimension(750, 460));//changes size to image with  border for buttons
                                                          //andlabels

    ImageIcon bG = new ImageIcon ("/Users/Documents/slotmachine.png");//background file
    JLabel backGround = new JLabel (bG);
    backGround.setBounds (70,0, bG.getIconWidth(), bG.getIconHeight());//won't display if you do not set bounds
    layeredPane.add (backGround, new Integer (0));//add to first layer

    /*add buttons and labels to give user options
     * and information, placed in layer 2 */

    playAgain.setBounds (110,420, 100, 25);
    layeredPane.add (playAgain, new Integer (2));
    playAgain.addActionListener (new Start());


    betButton.setBounds (320,420, 100, 25);
    layeredPane.add (betButton, new Integer (2));
    betButton.addActionListener (new SlotBB ());


    JButton mainMenu = new JButton ("Main Menu");
    mainMenu.setBounds (520,420, 100, 25);
    layeredPane.add (mainMenu, new Integer (2));
    long checkTime = System.currentTimeMillis ();
    System.out.println ("Total execution time : " + (checkTime - startTime));

    JLabel bet = new JLabel ("Bet:");
    bet.setBounds (620, 320, 100, 30);

    Font font = new Font ("Corsiva Hebrew",bet.getFont().getStyle(),30);  //desired font    & size

    bet.setFont (font);
    layeredPane.add (bet, new Integer (2));


    numberBet.setBounds (620, 340, 100, 30);
    layeredPane.add (numberBet, new Integer (2));
    numberBet.setFont (font);

    JLabel account = new JLabel ("Account: ");
    account.setBounds (5, 320, 150, 30);
    account.setFont (font);
    layeredPane.add (account, new Integer (2));

    numberAccount.setBounds (5, 340, 150, 30);
    numberAccount.setFont (font);
    layeredPane.add (numberAccount, new Integer (2));


     add(layeredPane);

    JComponent newContentPane = layeredPane;

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    frame.setBackground (Color.white);

    //Display the window.
    frame.pack();
    frame.setVisible(true);

}




public void run ()
{
  try {
    Thread.sleep (20);
    System.out.println ("works");
  }
  catch (Exception e) {
    System.out.println ("doesn't work");
  }

}




class Start extends JPanel implements ActionListener
{
  public void actionPerformed (ActionEvent event)
  { 
    SlotAnimator a0 = new SlotAnimator (40);
    a0.setBounds(155, 85, 100, 90); 
    layeredPane.add (a0, new Integer (1));

    SlotAnimator a1 = new SlotAnimator (85);
    a1.setBounds(320, 85, 100, 90); 
    layeredPane.add (a1, new Integer (1));

    SlotAnimator a2 = new SlotAnimator (135);
    a2.setBounds(470, 85, 100, 90); 
    layeredPane.add (a2, new Integer (1));
    playAgain.setText ("play again?");
    hearSound();

    thread = new Thread (new SlotMachineOpeningGraphic ());
    thread.start ();

  }
}



 public static void main (String [] args)
 {
   new SlotMachineOpeningGraphic();
 }
}

Any suggestions on an approach? It would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:09:30+00:00Added an answer on May 26, 2026 at 12:09 am

    @HFOE is right about using javax.swing.Timer, which manages its own thread to generate periodic GUI events in a safe way. You may also want to look at adopting the Model-View-Controller pattern, exemplified here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an application that simulates a slot machine. Now, I
I'm trying create this function such that if any key besides any of the
I'm trying to create simple slot machine with three slots. Each slot will generate
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying create a box in my Django app that displays text (and possibly
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I'm trying create a new file with a Java Applet, but I don't know
I am trying to solve a consumer/producer problem, and I have to create three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.