Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Slot Machine GUI

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Slot Machine GUI

    Hello! I am new to GUI Programming. We've been tasked to do a slot machine using GUI. I already made the base of the slot machine. The Problem is I cannot figure out how to input the random number generator on the two panels on the JTextField on each of them. Below is my code:


    package slotMachineMain;


    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Image;
    import java.awt.Toolkit;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;



    public class slot1 {

    public static void main(String[] args) {

    Image icon = Toolkit.getDefaultToolkit().getImage("D:\\11.png") ;
    ImageIcon image1 = new ImageIcon("D:\\12.png");
    ImageIcon image2 = new ImageIcon("D:\\13.gif");
    ImageIcon image3 = new ImageIcon("D:\\14.png");

    JFrame frame1 = new JFrame();
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
    frame1.setTitle("Take your Chance Here!");

    JLabel label1 = new JLabel();
    label1.setIcon(image1);
    label1.setBounds(120, 10, 138, 87);

    JLabel label2 = new JLabel();
    label2.setIcon(image2);
    label2.setBounds(0, 0, 400, 290);

    JTextField text1 = new JTextField();
    text1.setPreferredSize(new Dimension(80,80));
    text1.setEditable(false);

    JTextField text2 = new JTextField();
    text2.setPreferredSize(new Dimension(80,80));
    text2.setEditable(false);

    JPanel panel1 = new JPanel();
    panel1.setBackground(Color.white);
    panel1.setBounds(83, 100, 90, 90);
    panel1.add(text1);

    JPanel panel2 = new JPanel();
    panel2.setBackground(Color.white);
    panel2.setBounds(207, 100, 90, 90);
    panel2.add(text2);

    JButton button1 = new JButton();
    button1.setBounds(152, 200, 75, 25);
    button1.setIcon(image3);

    frame1.setResizable(false);
    frame1.setSize(400, 290);
    frame1.setLayout(null);
    frame1.setIconImage(icon);
    frame1.add(panel1);
    frame1.add(panel2);
    frame1.add(button1);
    frame1.add(label1);
    frame1.add(label2);
    frame1.setVisible(true);

    }


    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Slot Machine GUI

    how to input the random number generator on the two panels on the JTextField
    Can you explain that a little better. Do you mean you want a random number displayed in the JTextField in the panel?

    One problem I see with the posted code is that too much of the code is in the main method. Much of that code needs to be moved into the constructor or methods in the Slot1 class. Many of the variables need to be declared in the class, not in any method.
    Also the variable names need to be related to the data that they hold or what they are used for.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What Am I Doing Wrong With A Slot Machine Game?
    By zendorz in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 21st, 2013, 05:25 PM
  2. Slot Machine game in Java. using Net Beans.
    By leo24 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 28th, 2012, 10:32 PM
  3. Slot machine, animating the reels to spin
    By LukeDavison in forum Object Oriented Programming
    Replies: 3
    Last Post: November 27th, 2011, 10:59 AM
  4. Slot Machine
    By nemoisback66 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 17th, 2010, 01:57 PM

Tags for this Thread