View Single Post
  #7   Spotlight this post!  
Unread 24-01-2013, 06:45
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Toggling Buttons in Java

Quote:
Originally Posted by Ether View Post

Two different ways to turn a momentary-contact button into a toggle:

Code:
if ( buttonIsPressed() )              // test button state
    {
    if (!buttonWasPressed) toggle();  // toggle if state changed from "not pressed" to "pressed"
    buttonWasPressed=1;               // remember button state for next iteration
    }
else buttonWasPressed=0;              // remember button state for next iteration

I like this one better:

Code:
IsPressed = buttonIsPressed();          // get new button state

if (IsPressed && !WasPressed) toggle(); // toggle if state changed from "not pressed" to "pressed"

WasPressed=IsPressed;                   // remember button state for next iteration
What language is that? Buttons have no isPressed wasPressed etc
Reply With Quote