Java buttons not working

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 453 Views - Last Post: 06 December 2012 - 01:38 PM Rate Topic: -----

#16 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java buttons not working

Posted 06 December 2012 - 12:17 PM

so if you have
JButton[] btnHold = new JButton[3];
JButton[] btnSpin = new JButton[3];
and
Timer[] timer = new Timer[3];

then it is a piece of cake
    public void actionPerformed(ActionEvent e) {
      Object o = e.getSource();
      for(int i = 0; i < 3; i++) {
         if(o == btnSpin[i]) {
              timer[i].start();
              break;
         }
         if(o == btnHold[i]) {
              timer[i].stop();
              btnSpin[i].setEnable(false);
              break;
         }
       }
     }



But we are wasting our time talking about possible code based on code that we havan't seen
Was This Post Helpful? 1
  • +
  • -

#17 fvnbab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-November 12

Re: Java buttons not working

Posted 06 December 2012 - 01:25 PM

ok the problem was I had only one spin button
But I had 3 timers and 3 hold buttons
What i am trying to do is (sorry if i confused) is when a user click on Hold button 1 and hold button 2 the reel should not move --- The code you have given me does that, but after holding a button a user should be enabled to spin again which in this case reel 3 should only spin rather than reel one and two because they are in hold.

The only way I have solved is having 3 extra spin button. But i just want to confirm theres no way that i could fire addtional action listeners for only one button? (spin button so when a user clicks on it, It spins the reel 1 2 and 3 howeever when a user click on hold button 1 and 2 only reel 3 should spin AFter* clicking on spin again)

This post has been edited by fvnbab: 06 December 2012 - 01:27 PM

Was This Post Helpful? 0
  • +
  • -

#18 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java buttons not working

Posted 06 December 2012 - 01:38 PM

3 timers, 3 hold, one spin
public void actionPerformed(ActionEvent e) {
  Object o = e.getSource();

  if(o == btnSpin) {
      for(int i = 0; i < timer.length; ++i)
           timer[i].start();
      return;
  }

  for(int i = 0; i < 3; i++) {
     if(o == btnHold[i]) {
          timer[i].stop();
          btnSpin.setEnable(false);
          break;
     }
   }
 }


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2