Slot Machine

build a gambeling machine

Page 1 of 1

11 Replies - 5037 Views - Last Post: 16 November 2010 - 03:31 PM Rate Topic: -----

#1 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Slot Machine

Posted 15 November 2010 - 11:17 AM

I have wrote out the start of my coding to begin making a electronic gambeling machine and just had a few questions (i'm very very new to java btw):

the way i have set up my code is to display an error message once the credit drops below 0. at the moment the second the last go puts the credit to 0 it displays the error message i was wondering if someone could tell me how to make the message appear once the last go has been finished.

my second question is related to how i stop the credit going over £5. i have made it so that once the credit goes over 500 it displays and error message but if it is on a amount which isnt a whole number say 420 it will allow the balance to go to 520. i have spent around 4 hours + trying to figure it out. i am not looking for my work doing for me but would just appricate some tips as im getting frustrated that the answer is still aluding me..


MY CODE SO FAR!:
import java.awt.*;  
import java.awt.event.*;  
import java.util.*;  
import javax.swing.*;  
import javax.swing.Timer;  


public class ElectronicBandit extends JFrame implements ActionListener
{
  //list of all the variables in the project  
    
	private JButton btnInsertMoney, btnStart, btnBye;
	private JTextField txtcredit;
	private JLabel lblCredit, lblno1, lblno2, lblno3;
	private int credit = 0, counter = 0, spin1;
	private Random random;  
	private Icon icnMelon,icnOrange,icnBar,icnGrapes,icnLemon,icnBell,icnSeven,icnCherry; 
	private Timer timer1;
	
public static void main(String[] args)
{
	ElectronicBandit  ElectronicBandit = new ElectronicBandit();
}

public ElectronicBandit()
{
  //definitions of all the variables detailed above (basically put all the buttons the window)
	    
    		JOptionPane.showMessageDialog(null,"Hello and welcome to Electronic Bandit!!");
    		    	    
    		setLayout(new FlowLayout());
		
    		timer1 = new Timer(300, this); 
    		random = new Random(); 
    	    
    		lblCredit = new JLabel ("Credit");
    		lblCredit.setFont(new Font("TimesRoman", Font.BOLD, 16));
    		
    		txtcredit= new JTextField(3);
		txtcredit.setFont(new Font("TimesRoman", Font.BOLD, 16));
		txtcredit.setBackground(Color.green);
		txtcredit.setForeground(Color.red);
		txtcredit.setText(credit + " ");
		
		lblno1 = new JLabel ("");
		lblno1.setPreferredSize(new Dimension(150, 150));
		lblno1 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno1.setBackground(Color.white);
			
		lblno2 = new JLabel ("");
		lblno2.setPreferredSize(new Dimension(150, 150));
		lblno2 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno2.setBackground(Color.white);
		
		lblno3= new JLabel ("");
		lblno3.setPreferredSize(new Dimension(150, 150));
		lblno3 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno3.setBackground(Color.white);
		
		btnInsertMoney = new JButton("Insert £1.00");
		btnStart = new JButton("Start");
		btnStart.setEnabled(false);
		btnBye = new JButton("Bye!!");
		
		icnMelon = new ImageIcon("bin/Melon.jpg");
		icnOrange = new ImageIcon("bin/Orange.jpg");
		icnBar = new ImageIcon("bin/Bar.jpg");
		icnGrapes = new ImageIcon("bin/Grapes.jpg");
		icnLemon = new ImageIcon("bin/Lemon.jpg");
		icnBell= new ImageIcon("bin/Bell.jpg");
		icnSeven = new ImageIcon("bin/Seven.jpg");
		icnCherry = new ImageIcon("bin/Cherry.jpg");
		
                add(txtcredit); 
                add(lblCredit); add(lblno1); add(lblno2); add(lblno3); 
                add(btnInsertMoney); add(btnStart); add(btnBye);
                

                btnInsertMoney.addActionListener(this);
		btnStart.addActionListener(this);
		btnBye.addActionListener(this);
		
		setTitle("Simple GUI Demo. . . .");
		setSize(1000, 1000);
		setVisible(true);
	}
	
public void actionPerformed(ActionEvent event)
{
// this states that once the button insert money is pressed it increases the balance by 100 (£1)
	    	if (event.getSource()== btnInsertMoney){
			txtcredit.setForeground(Color.black);
			credit = credit + 100;
			txtcredit.setText(credit + " ");
		}
	    	
		// this is the increment money function. 
		// the first if statement disables the button if the total becomes equal to 500 (£5)
		if (credit >= 500)
		{  
		    btnInsertMoney.setEnabled(false);  
		    JOptionPane.showMessageDialog(null,"Maximum Pay In Reached, Time to Start Playing!!");
		}  
		
		// the second statement re-enables the button once the balance goes back below 0 
				if (credit <= 0)
		{  
		    btnInsertMoney.setEnabled(true);  
		}  
		
		// this is the decrement money function. 
		// the first if statement disables the button if the total becomes equal to 0 or goes below
				if (credit <= 0)
		{  
		    btnStart.setEnabled(false);  
		    JOptionPane.showMessageDialog(null,"Insert More Money to Continue!!");
		}  
		
		// the second statement enables the button once the balance goes back above 20
		if (credit >= 20)
		{  
		    btnStart.setEnabled(true);  
		}  
		
		// this states that once the button decrement is pressed it decreases the balance by 20 (20) and starts the timer
		if (event.getSource()== btnStart)
		{
		    	counter = 0;   
		    	timer1.start();  
		  		    
		    	txtcredit.setForeground(Color.red);
			credit = credit - 20;
			txtcredit.setText(credit + " ");
				
		}
		
		if (event.getSource()== timer1)
		{  
		    setIcon1();  
		}  
		
		// this states that once the button bye is pressed the program is closed
		if (event.getSource()== btnBye)
		{
			System.exit(0);
		}
	
	}

private void setIcon1()
	{ 
            	spin1= random.nextInt(8);
        	switch (spin1)
        	{
                	case 1:
                	lblno1.setIcon(icnMelon);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 2:
                	lblno1.setIcon(icnOrange);
                	counter =  counter + 1;  
                	
                	break;
                	case 3:
                	lblno1.setIcon(icnBar);
                	counter =  counter + 1;  
                	
                	break;
                		
                	case 4:
                	lblno1.setIcon(icnGrapes);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 5:
                	    
                	lblno1.setIcon(icnLemon);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 6:
                	lblno1.setIcon(icnBell);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 7:
                	lblno1.setIcon(icnSeven);
                	counter =  counter + 1; 
                	
                	break;
                	
                	case 8:
                	lblno1.setIcon(icnCherry);
                	counter =  counter + 1;  
                	
                	break;	
          	}
        	
        	if (counter ==10) 
        	    timer1.stop(); 
        }
}


This post has been edited by macosxnerd101: 15 November 2010 - 11:19 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Slot Machine

#2 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 123
  • View blog
  • Posts: 720
  • Joined: 15-October 09

Re: Slot Machine

Posted 15 November 2010 - 11:53 AM

This check:

		// this is the increment money function.
		// the first if statement disables the button if the total becomes equal
		// to 500 (£5)
		if (credit >= 500) {
			btnInsertMoney.setEnabled(false);
			JOptionPane.showMessageDialog(null,
					"Maximum Pay In Reached, Time to Start Playing!!");
		}



should be in the following if:

		
if (event.getSource() == btnInsertMoney) {



(it's when you insert that you have to check that you’ve reached the limit)

and this check:

			// this is the decrement money function.
			// the first if statement disables the button if the total becomes equal
			// to 0 or goes below
			if (credit <= 0) {
				btnStart.setEnabled(false);
				JOptionPane.showMessageDialog(null,
						"Insert More Money to Continue!!");
			}



should be in the following if:

		if (event.getSource() == btnStart) {



(it's when you've finished playing that you should whether you have enough to carry on)

Generally speaking, you should perform the checks only in if (event.getSource() == ...) statements, as they should be done when you click on a button.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_xenohadden*


Reputation:

Re: Slot Machine

Posted 15 November 2010 - 01:03 PM

thanks for getting back to me so fast mate. i understand what you mean as have managed to move the first part that was in the wrong place, but how do i put an if statement like you suggested together, can i have an if within an if?

would :

if (event.getSource() == btnStart)
if (credit <= 0)
{ btnStart.setEnabled(false);
JOptionPane.showMessageDialog(null,
"Insert More Money to Continue!!");
}

be right or am i still confused?


View PostEdwinNameless, on 15 November 2010 - 10:53 AM, said:

This check:

		// this is the increment money function.
		// the first if statement disables the button if the total becomes equal
		// to 500 (£5)
		if (credit >= 500) {
			btnInsertMoney.setEnabled(false);
			JOptionPane.showMessageDialog(null,
					"Maximum Pay In Reached, Time to Start Playing!!");
		}



should be in the following if:

		
if (event.getSource() == btnInsertMoney) {



(it's when you insert that you have to check that you’ve reached the limit)

and this check:

			// this is the decrement money function.
			// the first if statement disables the button if the total becomes equal
			// to 0 or goes below
			if (credit <= 0) {
				btnStart.setEnabled(false);
				JOptionPane.showMessageDialog(null,
						"Insert More Money to Continue!!");
			}



should be in the following if:

		if (event.getSource() == btnStart) {



(it's when you've finished playing that you should whether you have enough to carry on)

Generally speaking, you should perform the checks only in if (event.getSource() == ...) statements, as they should be done when you click on a button.

Was This Post Helpful? 0

#4 Guest_xenohadden*


Reputation:

Re: Slot Machine

Posted 15 November 2010 - 01:28 PM

being playing around with it in my java builder (Java SE6) and think something like:
{
			    	if (credit >=0)
			    		
			    	{
			    		btnStart.setEnabled(true);
			    		counter = 0;   
			    		timer1.start();  
			    		txtcredit.setForeground(Color.red);
			    		credit = credit - 20;
			    		txtcredit.setText(credit + " ");
			    	}
				
			    	else if (credit >=20)
			    	{
			    		btnStart.setEnabled(false);  
					    JOptionPane.showMessageDialog(null,"Insert More Money to Continue!!");
			    	}
				}



should work but for some reason the button isnt being enabled once the credit goes over 20?



View Postxenohadden, on 15 November 2010 - 12:03 PM, said:

thanks for getting back to me so fast mate. i understand what you mean as have managed to move the first part that was in the wrong place, but how do i put an if statement like you suggested together, can i have an if within an if?

would :

if (event.getSource() == btnStart)
if (credit <= 0)
{ btnStart.setEnabled(false);
JOptionPane.showMessageDialog(null,
"Insert More Money to Continue!!");
}

be right or am i still confused?


View PostEdwinNameless, on 15 November 2010 - 10:53 AM, said:

This check:

		// this is the increment money function.
		// the first if statement disables the button if the total becomes equal
		// to 500 (£5)
		if (credit >= 500) {
			btnInsertMoney.setEnabled(false);
			JOptionPane.showMessageDialog(null,
					"Maximum Pay In Reached, Time to Start Playing!!");
		}



should be in the following if:

		
if (event.getSource() == btnInsertMoney) {



(it's when you insert that you have to check that you’ve reached the limit)

and this check:

			// this is the decrement money function.
			// the first if statement disables the button if the total becomes equal
			// to 0 or goes below
			if (credit <= 0) {
				btnStart.setEnabled(false);
				JOptionPane.showMessageDialog(null,
						"Insert More Money to Continue!!");
			}



should be in the following if:

		if (event.getSource() == btnStart) {



(it's when you've finished playing that you should whether you have enough to carry on)

Generally speaking, you should perform the checks only in if (event.getSource() == ...) statements, as they should be done when you click on a button.

This post has been edited by macosxnerd101: 15 November 2010 - 02:20 PM
Reason for edit:: Added code tags.

Was This Post Helpful? 0

#5 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Re: Slot Machine

Posted 15 November 2010 - 01:47 PM

i know ive answered alot of my own questions with the help of you ofc :P

have amended my code and its works correctly now:
import java.awt.*;  
import java.awt.event.*;  
import java.util.*;  
import javax.swing.*;  
import javax.swing.Timer;  


public class Build1 extends JFrame implements ActionListener
	{
		//list of all the variables in the project  
		private JButton btnInsertMoney, btnStart, btnBye;
		private JTextField txtcredit;
		private JLabel lblCredit, lblno1, lblno2, lblno3;
		private int credit = 0, counter = 0, spin1;
		private Random random;  
		private Icon icnMelon,icnOrange,icnBar,icnGrapes,icnLemon,icnBell,icnSeven,icnCherry; 
		private Timer timer1;
	
	
public static void main(String[] args)
	{
		Build1  Build1 = new Build1();
	}

public Build1()
	{
		//definitions of all the variables detailed above (basically put all the buttons the window)
	 
    	JOptionPane.showMessageDialog(null,"Hello and welcome to Electronic Bandit!!");
    		    	    
    	setLayout(new FlowLayout());
		
    	timer1 = new Timer(300, this); 
    	random = new Random(); 
    	    
    	lblCredit = new JLabel ("Credit");
    	lblCredit.setFont(new Font("TimesRoman", Font.BOLD, 16));
    		
    	txtcredit= new JTextField(3);
		txtcredit.setFont(new Font("TimesRoman", Font.BOLD, 16));
		txtcredit.setBackground(Color.green);
		txtcredit.setForeground(Color.red);
		txtcredit.setText(credit + " ");
		
		lblno1 = new JLabel ("");
		lblno1.setPreferredSize(new Dimension(150, 150));
		lblno1 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno1.setBackground(Color.white);
			
		lblno2 = new JLabel ("");
		lblno2.setPreferredSize(new Dimension(150, 150));
		lblno2 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno2.setBackground(Color.white);
		
		lblno3= new JLabel ("");
		lblno3.setPreferredSize(new Dimension(150, 150));
		lblno3 .setFont(new Font("TimesRoman", Font.BOLD,50));
		lblno3.setBackground(Color.white);
		
		btnInsertMoney = new JButton("Insert £1.00");
		btnStart = new JButton("Start");
		btnStart.setEnabled(false);
		btnBye = new JButton("Bye!!");
		
		icnMelon = new ImageIcon("bin/Melon.jpg");
		icnOrange = new ImageIcon("bin/Orange.jpg");
		icnBar = new ImageIcon("bin/Bar.jpg");
		icnGrapes = new ImageIcon("bin/Grapes.jpg");
		icnLemon = new ImageIcon("bin/Lemon.jpg");
		icnBell= new ImageIcon("bin/Bell.jpg");
		icnSeven = new ImageIcon("bin/Seven.jpg");
		icnCherry = new ImageIcon("bin/Cherry.jpg");
		
        add(txtcredit); 
        add(lblCredit); add(lblno1); add(lblno2); add(lblno3); 
        add(btnInsertMoney); add(btnStart); add(btnBye);
                
        btnInsertMoney.addActionListener(this);
		btnStart.addActionListener(this);
		btnBye.addActionListener(this);
		
		setTitle("Simple GUI Demo. . . .");
		setSize(1000, 1000);
		setVisible(true);
	}
	
public void actionPerformed(ActionEvent event)
	{
		// this states that once the button insert money is pressed it increases the balance by 100 (£1)
	    if (event.getSource()== btnInsertMoney)
	    	{
	    		txtcredit.setForeground(Color.black);
	    		credit = credit + 100;
	    		txtcredit.setText(credit + " ");
	    		
	    		// this is the increment money function. 
	    		// the first if statement disables the button if the total becomes equal to 500 (£5)
	    		if (credit >= 500)
	    			{  
	    				btnInsertMoney.setEnabled(false);  
	    				JOptionPane.showMessageDialog(null,"Maximum Pay In Reached, Time to Start Playing!!");
	    			}  
	    		
	    		// the second statement re-enables the button once the balance goes back below 0 
	    		if (credit <= 0)
					{  
						btnInsertMoney.setEnabled(true);  
					} 
	    		
	    		// the second statement enables the button once the balance goes back above 20
	    		if (credit >= 20)
				{  
					btnStart.setEnabled(true);  
				} 
	    	}
	  
		// this states that once the button decrement is pressed it decreases the balance by 20 (20) and starts the timer
		if (event.getSource()== btnStart)
			{
		    	counter = 0;   
		    	timer1.start();  
		  		    
		    	txtcredit.setForeground(Color.red);
		    	credit = credit - 20;
		    	txtcredit.setText(credit + " ");
			
		    	if (credit <= 0)
		    		{  
		    			btnStart.setEnabled(false);  
		    			JOptionPane.showMessageDialog(null,"Insert More Money to Continue!!");
		    		}  		
			}
		
		if (event.getSource()== timer1)
		{  
		    setIcon1();  
		}  
		
		// this states that once the button bye is pressed the program is closed
		if (event.getSource()== btnBye)
		{
			System.exit(0);
		}
	
	}

private void setIcon1()
	{ 
            	spin1= random.nextInt(8);
        	switch (spin1)
        	{
                	case 1:
                	lblno1.setIcon(icnMelon);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 2:
                	lblno1.setIcon(icnOrange);
                	counter =  counter + 1;  
                	
                	break;
                	case 3:
                	lblno1.setIcon(icnBar);
                	counter =  counter + 1;  
                	
                	break;
                		
                	case 4:
                	lblno1.setIcon(icnGrapes);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 5:
                	    
                	lblno1.setIcon(icnLemon);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 6:
                	lblno1.setIcon(icnBell);
                	counter =  counter + 1;  
                	
                	break;
                	
                	case 7:
                	lblno1.setIcon(icnSeven);
                	counter =  counter + 1; 
                	
                	break;
                	
                	case 8:
                	lblno1.setIcon(icnCherry);
                	counter =  counter + 1;  
                	
                	break;	
          	}
        	
        	if (counter ==10) 
        	    timer1.stop(); 
        }
}


however the code is still allowing the users balances to go above 500 and then displaying the message so say they have 430 it goes to 530 then says to much money inserted and turns of the button. i want it to not allow the balance to go over 500.

second the second error i mentioned is still happening :( the program allows the last 20p to be spent but whilst spinning pops up with the message to insert more money, rather than waiting till the end of the spin and the providing the message. any ideas?

This post has been edited by macosxnerd101: 15 November 2010 - 02:21 PM
Reason for edit:: Please use code tags.

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Slot Machine

Posted 15 November 2010 - 09:13 PM

You are doing

counter = counter + 1;

in every case statement inside your switch() better to do it only once after the switch

and an array will be a lot more efficient

ImageIcon[] icon = {icnMelon, icnOrange, icn.....};
spin1 = random.nextInt(8);
lblNo1.setIcon(icon[spin1]);
counter++;

and dont't forget that random.nextInt(8); might return 0
Was This Post Helpful? 0
  • +
  • -

#7 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Re: Slot Machine

Posted 16 November 2010 - 03:28 AM

ah i think i get what you mean, but my teacher hasnt mentioned arrays yet, is that what you meant by:

[b][i]ImageIcon[] icon = {icnMelon, icnOrange, icn.....};[/i][/b]



if so i think i get what to do change the code for my counter to look like this:

{
ImageIcon []icon = {icnMelon, icnOrange, icnBar,icnGrapes,icnLemon,icnBell,icnSeven,icnCherry};
spin1 = random.nextInt(8); 
lblno1.setIcon(icon[spin1]);
}
counter++;



but when it trys to compile this i get alot of errors, so am i miss understanding how the array works?





View Postpbl, on 15 November 2010 - 08:13 PM, said:

You are doing

counter = counter + 1;

in every case statement inside your switch() better to do it only once after the switch

and an array will be a lot more efficient

ImageIcon[] icon = {icnMelon, icnOrange, icn.....};
spin1 = random.nextInt(8);
lblNo1.setIcon(icon[spin1]);
counter++;

and dont't forget that random.nextInt(8); might return 0

Was This Post Helpful? 0
  • +
  • -

#8 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Re: Slot Machine

Posted 16 November 2010 - 03:37 AM

i got:


{
				ImageIcon []icon = {(ImageIcon) icnMelon, (ImageIcon)icnOrange, (ImageIcon)icnBar,(ImageIcon)icnGrapes,(ImageIcon)icnLemon,(ImageIcon)icnBell,(ImageIcon)icnSeven,(ImageIcon)icnCherry};
			spin1 = random.nextInt(7); 
			lblno1.setIcon(icon[spin1]);
			counter++;
			}




to work but could you just run through how and what this does a i dont want to put something i my assignement if i dont fully understand what it is actually doing.

kind regards,


carl




View Postpbl, on 15 November 2010 - 08:13 PM, said:

You are doing

counter = counter + 1;

in every case statement inside your switch() better to do it only once after the switch

and an array will be a lot more efficient

ImageIcon[] icon = {icnMelon, icnOrange, icn.....};
spin1 = random.nextInt(8);
lblNo1.setIcon(icon[spin1]);
counter++;

and dont't forget that random.nextInt(8); might return 0

Was This Post Helpful? 0
  • +
  • -

#9 Guest_xenohadden*


Reputation:

Re: Slot Machine

Posted 16 November 2010 - 05:44 AM

anyone able to explain to me?
Was This Post Helpful? 0

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: Slot Machine

Posted 16 November 2010 - 07:25 AM

Basically, you have declared an array of ImageIcons. These ImageIcons are grouped into an element with a single name, and you access the ImageIcons by a numerical index. The Random Object generates a Random number to choose an ImageIcon, and that ImageIcon is set for the JLabel.
Was This Post Helpful? 0
  • +
  • -

#11 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Re: Slot Machine

Posted 16 November 2010 - 08:03 AM

as thanks very much think i get it now. if that was the case im guessing :


{
ImageIcon []icon = {(ImageIcon) icnMelon, (ImageIcon)icnOrange, (ImageIcon)icnBar,(ImageIcon)icnGrapes,(ImageIcon)icnLemon,(ImageIcon)icnBell,(ImageIcon)icnSeven,(ImageIcon)icnCherry};
spin1 = random.nextInt(7);
lblno1.setIcon(icon[spin1]);
counter++;
}




would be incorrect then, even though it appears to be working, wouldnt i need to declare a number for each image icon in the array?


thanks for the help so far, really helping me with getting my head round this :P


View Postmacosxnerd101, on 16 November 2010 - 06:25 AM, said:

Basically, you have declared an array of ImageIcons. These ImageIcons are grouped into an element with a single name, and you access the ImageIcons by a numerical index. The Random Object generates a Random number to choose an ImageIcon, and that ImageIcon is set for the JLabel.

Was This Post Helpful? 0
  • +
  • -

#12 xenohadden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-November 10

Re: Slot Machine

Posted 16 November 2010 - 03:31 PM

I have managed to get my fruit machine to work as intended now, the nudge buttons work and it records credit / banked money ect. i even managed to get it to play a sound when it spins! (WEEE, might not be much for people but im enjoying this!).

i do however want to add a few more thingys to my machine and just had a quick two questions that i hope someone could help me with:

question 1: i am trying to produce some hold buttons now and this is the code for them so far.

 //the coding for what happens when the first hold button is pressed
 if(event.getSource() == btnHold1) 
     {
	// this part of the code stop the timer which is running the first spinner.
	timer1.stop();

        //this part of the code also disables all the hold buttons ( the reason for this being i am only allowing them to hold one of the reels
	btnHold1.setEnabled(false);
	btnHold2.setEnabled(false);
	btnHold3.setEnabled(false);

	return;
      }



before anyone says yes i have declared the buttons ect in my code and implemented the action listener. how i dont think the way i have writen the action event for the hold button is correct and just wondered if someone could point me in the right direction.

question 2: now i know this is a bit complex for someone who is just starting out with java but i want to include a record log of all games that can only be accessed via password entry (like when a maintaince guy checks a machines logs).

to do this im guessing i should create new intergers for each picture type and add something like (Lemon= Lemon +1;) to each case within my code. then i would need a way to display this in a new jpane(possibly) and is it even possible to make a user enter a password to view a new jpane?

any help / advise you can give me would be great. i can provide my full coding if nessery but i want guidence not it doing for me so i can understand it (trying really hard to grasp java :P)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1