1 Replies - 1661 Views - Last Post: 08 December 2009 - 02:22 PM Rate Topic: -----

#1 zinger549  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 09

Slot Machine spinng pictures

Posted 08 December 2009 - 02:19 PM

I am having problems with my slot machine. I am trying to get the pictures to spin when the spin button is pressed. The first code is the one i'm trying to use to spin the pictures.
if (event.getSource() == btnSpin ){
					counter = 0;
					timer = new Timer(600, this);
					timer2 = new Timer(600, this);
					timer3 = new Timer(600, this);
					timer.start();
					timer2.start();
					timer3.start();
				}
				  
					
					switch (num){
						case 1:
							lbl1.setIcon(iconPic1);
							lemon = lemon +1;
							counter =  counter + 1;
							break;
						case 2:
							lbl1.setIcon(iconPic2);
							cherry = cherry +1;
							counter =  counter + 1;
							break;
						case 3:
							lbl1.setIcon(iconPic3);
							seven= seven +1;
							counter =  counter + 1;
							break;
						case 4:
							lbl1.setIcon(iconPic4);
							Bell= Bell +1;
							counter =  counter + 1;
							break;
						case 5:
							lbl1.setIcon(iconPic5);
							Bar = Bar +1;
							counter =  counter + 1;
							break;
						case 6:
							lbl1.setIcon(iconPic6);
							watermelon = watermelon +1;
							counter =  counter + 1;
							break;
						case 7:
							lbl1.setIcon(iconPic7);
							Orange = Orange +1;
							counter =  counter + 1;
							break;
						case 8:
							lbl1.setIcon(iconPic7);
							BlueBerry= BlueBerry+1;
							counter =  counter + 1;
							break;
							}
				}
					
							
			
					
							switch (num){
							case 1:
								lbl1.setIcon(iconPic1);
								lemon = lemon +1;
								counter =  counter + 1;
								break;
							case 2:
								lbl1.setIcon(iconPic2);
								cherry = cherry +1;
								counter =  counter + 1;
								break;
							case 3:
								lbl1.setIcon(iconPic3);
								seven= seven +1;
								counter =  counter + 1;
								break;
							case 4:
								lbl1.setIcon(iconPic4);
								Bell= Bell +1;
								counter =  counter + 1;
								break;
							case 5:
								lbl1.setIcon(iconPic5);
								Bar = Bar +1;
								counter =  counter + 1;
								break;
							case 6:
								lbl1.setIcon(iconPic6);
								watermelon = watermelon+1;
								counter =  counter + 1;
								break;
							case 7:
								lbl1.setIcon(iconPic7);
								Orange = Orange +1;
								counter =  counter + 1;
								break;
							case 8:
								lbl1.setIcon(iconPic7);
								BlueBerry= BlueBerry+1;
								counter =  counter + 1;
								break;
							}
							}
					}
			switch (num){
			case 1:
				lbl1.setIcon(iconPic1);
				lemon = lemon +1;
				counter =  counter + 1;
				break;
			case 2:
				lbl1.setIcon(iconPic2);
				cherry = cherry +1;
				counter =  counter + 1;
				break;
			case 3:
				lbl1.setIcon(iconPic3);
				seven= seven +1;
				counter =  counter + 1;
				break;
			case 4:
				lbl1.setIcon(iconPic4);
				Bell= Bell +1;
				counter =  counter + 1;
				break;
			case 5:
				lbl1.setIcon(iconPic5);
				Bar = Bar +1;
				counter =  counter + 1;
				break;
			case 6:
				lbl1.setIcon(iconPic6);
				watermelon = watermelon +1;
				counter =  counter + 1;
				break;
			case 7:
				lbl1.setIcon(iconPic7);
				Orange = Orange +1;
				counter =  counter + 1;
				break;
			case 8:
				lbl1.setIcon(iconPic7);
				BlueBerry= BlueBerry+1;
				counter =  counter + 1;
				break;
				  


	import javax.swing.*;

	import java.awt.*;
import java.awt.event.*;
import java.util.Random;
	public class Ebandit extends JFrame implements ActionListener
	{
		private JButton btnAddmoney, btnSpin, btnBye,btnHold, btnHold2,btnHold3;
		private int k = 0;
		private int counter;
		private JTextField txtNum,txtWinnings;
		private JPanel Panelslot1,Panelslot2,Panelslot3;
		private JLabel lbl1, lbl2, lbl3;
		private int num;
		private Timer timer,timer2,timer3;
		private Icon iconPic1, iconPic2, iconPic3, iconPic4, iconPic5, iconPic6, iconPic7, iconPic8;
		private int lemon, cherry, seven, Bell, Bar, watermelon, Orange, BlueBerry;
		private int[] Num = new int[3];
		private int cash = 0;
		private int winnings =0;

		public static void main(String[] args)
		{
			Ebandit Spin = new 
			Ebandit();
		}

		public Ebandit()
		{
		
			setLayout(new FlowLayout());
			txtNum = new JTextField(3);
			txtNum.setFont(new Font("TimesRoman", Font.BOLD, 16));
			txtNum.setBackground(Color.green);
			txtNum.setForeground(Color.red);
			txtNum.setText(num + " ");
			btnAddmoney = new JButton("1");
			btnSpin = new JButton("Spin");
			btnSpin.setEnabled(false);
			btnBye = new JButton("Cash!!");
			btnHold = new JButton ("Hold");
			btnHold2 = new JButton ("Hold");
			btnHold3 = new JButton ("Hold");
			  
			iconPic1 = new ImageIcon("bin/lemon.gif");
			  iconPic2 = new ImageIcon("bin/cherry.gif");
			  iconPic3 = new ImageIcon("bin/Seven.gif");
			  iconPic4 = new ImageIcon("bin/Bell.gif");
			  iconPic5 = new ImageIcon("bin/Bar.gif");
			  iconPic6 = new ImageIcon("bin/water melon.gif");
			  iconPic7 = new ImageIcon("bin/Orage.gif");
			  iconPic8 = new ImageIcon ("bin/Bule Berry.gif");
							add(txtNum);add(btnAddmoney);
							add(btnSpin);add(btnBye);
						   
						   
							
			btnAddmoney.addActionListener(this);
			btnSpin.addActionListener(this);
			btnBye.addActionListener(this);
			btnHold.addActionListener(this);
			btnHold2.addActionListener(this);
			btnHold3.addActionListener(this);
			setTitle("Electronic Bandit. . . .");
			setSize(400,350);
			setVisible(true);
			
			lbl1 = new JLabel();
			lbl1.setPreferredSize(new Dimension(100, 100));
			lbl1.setBackground(Color.gray);
			Panelslot1 = new  JPanel();
			Panelslot1.setBackground(Color.white);
			Panelslot1.add(lbl1);
		  
			
			lbl2 = new JLabel();
			lbl2.setPreferredSize(new Dimension(100, 100));
			lbl2.setBackground(Color.gray);
			Panelslot2 = new  JPanel();
			Panelslot2.setBackground(Color.white);
			Panelslot2.add(lbl2); 
			
			
			lbl3 = new JLabel();
			lbl3.setPreferredSize(new Dimension(100, 100));
			lbl3.setBackground(Color.gray);
			Panelslot3= new  JPanel();
			Panelslot3.setBackground(Color.white);
			Panelslot3.add(lbl3);
			
			
			add(Panelslot1);
			add(Panelslot2);
			add(Panelslot3);
			
			add(btnHold);
			add(btnHold2);
			add(btnHold3);
			
		
		}
	
			
		
		
			
		
		
		
	
	
		
		
		
		
	public void actionPerformed(ActionEvent event){
	{
	

	if (event.getSource()== btnAddmoney){
				txtNum.setForeground(Color.black);
				num = num + 100;
				txtNum.setText(num + " ");
				if(num>400)
					btnAddmoney.setEnabled( false );
					if(num>10)
						btnSpin.setEnabled ( true );
			}
			if (event.getSource()== btnSpin){
				txtNum.setForeground(Color.black);
				num = num - 20;
				txtNum.setText(num + " ");
				if(num<20)
				btnSpin.setEnabled( false );
				else 
					if(num<400)
						btnAddmoney.setEnabled(true);
				
				if (event.getSource()== btnBye){
				System.exit(0);
				
				

	}
	
	}
	}
	



This post has been edited by zinger549: 08 December 2009 - 02:41 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Slot Machine spinng pictures

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Slot Machine spinng pictures

Posted 08 December 2009 - 02:22 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1