Hi,
I'm trying to write the code for a hold button on a fruit machine. Im not sure where to start or how to do it.
Can anyone help me please and point me in the right direction
Thank You
Printable View
Hi,
I'm trying to write the code for a hold button on a fruit machine. Im not sure where to start or how to do it.
Can anyone help me please and point me in the right direction
Thank You
Start out with a detailed description of a problem to be solved. "...trying to write the code for a hold button on a fruit machine..." is not very detailed and tells very little.
Once you have that, figure out a process to solve the problem without thinking about code.
From that point it will be easier to write the code to solve the problem.
i have given it a try but i dont understand why it wont work. I have set a timer for each real and when the hold button is selected the timer stops so that reel doesnt spin. However the reel still spins.
the code i have for the reels which seem to work fine are:
Code :
if(event.getSource()==btnStart){ counter = 0; timer1 = new Timer(50,this); timer1.start(); timer2 = new Timer(50,this); timer2.start(); timer3 = new Timer(50,this); timer3.start(); } if(event.getSource()==timer1) { setIcon1 (); } if(event.getSource()==timer2) { setIcon2 (); } if(event.getSource()==timer3) { setIcon3 (); } if(event.getSource()==timer1){ timer1.stop(); } if(event.getSource()==timer2){ timer2.stop(); } if(event.getSource()==timer3){ timer3.stop(); } } } public void stopTimer1(){ timer1.stop(); } public void stopTimer2(){ timer2.stop(); } public void stopTimer3(){ timer3.stop(); }
the code for hold button which doesnt work is:
Code :
if(event.getSource()== btnHoldLeft){ timer1.stop(); } if(event.getSource()== btnHoldMiddle){ timer2.stop(); } if(event.getSource()== btnHoldRight){ timer3.stop(); }
am i missing something in the coding for the hold buttons?
What variable(s) controls that action? Try debugging the code by adding println statements that print out the values of all the variables used when they are changed and used.Quote:
the reel still spins.
Could you make a small complete program that compiles, executes and shows the problem?