Jbutton: Button held down or clicked

Hello. I am implementing an mp3 player in Java. I want to implement a button that behaves differently when it is held down and when it is just clicked. For example, when the button is held down,fast forward is called. When the button is just clicked, it goes to the next song in the playlist.
I have tried to implement this with the mouse listeners mouseclicked, pressed and released but it is hard to get only one action happening at a time. My main question is how do you differentiate betwen a button being held down and a button just being clicked?
here is a snippet of my non functional code:
nextSongButton.addMouseListener(new MouseAdapter() {
// go to next song
public void mouseClicked(MouseEvent event) {
System.out.println("entering mouseclicked");
int m = event.getModifiers();
System.out.println(event.getClickCount());
if ((event.getClickCount() == 1) && ((m & InputEvent.BUTTON1_MASK) != 0 )) {
mp3Playlist.playNextSong();
updateFileInfo();
// Do fast forward
public void mousePressed(MouseEvent event) {
System.out.println("entering mousepressed");
if (fastForwardState.equals("OFF")) {
mp3Playlist.fastForward();
fastForwardState = "ON";
// Go back to normal play
public void mouseReleased(MouseEvent event) {
System.out.println("entering mousereleased");
mp3Playlist.normalPlayback();
fastForwardState = "OFF";
Any code sample similar to the above would be very helpfull. Maybe I can implement this with some kind of timer delay? It could trigger after the button is held down for half a second.
Thank you very much for your help.

The thought that first occurs to me is to use a thread. Start the thread in mousePressed and kill it in mouseReleased. The thread will wait 1 sec, then 'turn on' FF (unless it gets killed first). Also stop FF in mouseReleased.

Similar Messages

  • Mac shuts down if I do not keep either the Fn, Command or control button held down ?

    Hi. I have a mac book pro late 2011 model. I am running Mavericks but but I have a problem where my mac shuts down if I do not keep either the Fn, Command or control button held down. Also if/when this shut down happens I need to hold the shift-control-option keys to restart the mac.
    Anybody got any advice for me ?
    Many thanks
    Paul

    Try resetting the SMC.
    Barry

  • My iPad3 received messages had no content. Solved: 2click home button, hold down mail, click  - upper left, click home

    My iPad3 received messages had no content. Solved: 2click home button, hold down mail, click  - upper left, click home

    That's great. That has also been posted countless times on this forum.

  • Rand new iPhone 5s black, dead, won't power up after ios 7 upgrade...held down top button, held down home button...dead. Was fully charged, working fine tell said yes to upgrade. HELP!!!

    Brand new  iPhone 5s dead, black won't come on after ios update...is fully charged, was working fine till said yes to upgrade. Did not watch process beyond seeing Apple logo appear, left it alone, came back, dead. Tried holding top button, tried home button, nothing...HELP!!!

    If iTunes does not recognize your iPhone even if it’s plugged in, you may need to put it into DFU (Device Firmware Update) mode. If you have to put the device in DFU mode, you will most likely be unable to back it up.
    Hold Power button for 3 seconds and then the Power and Home together for 10 seconds (exactly).
    Release Power but keep holding home until the your iPhone shows up in iTunes.

  • My screen continually freezes up.  I've tried closing all apps that are openfreezby double clicking on the home button and closing them. I have held down on the home button and start button simultaneously and it still freezes. Can someone out the help me?

    MY screen continually freezes up. I've tried closing all apps that are open and have held down the home button and start button simultaneously but neither helped. Can someone out there help me?

    Well the next couple of things to try would be to reset all settings, and if that doesn't help, it's probably time to restore the iOS software.
    Settings>General>Reset>Reset all settings. That will take all settings on the iPad back to factory defaults. It will not delete anything and you will not lose any data, but you will have to enter all settings again ...WiFi passwords, enable Siri, select your wallpaper, adjust brightness, turn on location services and set privacy settings, etc, etc.
    You can read about restoring the software here.
    iTunes: Restoring iOS software - Support - Apple
    Should you decide to restore the iOS, it is extremely important that you back up first so that you can restore from the backup and then sync with iTunes afterward in order to restore all content back to the iPad. It is all covered in the kb article.
    If you do not sync with iTunes, then I assume that you backup with iCloud. In that case you can erase the device in Settings>General>Reset>Erase all content and settings. Once again, backing up with I loud is I,operative before you do this so that you can restore from the iCloud backup after you erase the iPad and start over again with activation.
    You should read this first before you restore from either backup.
    How to backup and restore from a backup
    http://support.apple.com/kb/HT1766
    This is a must read before you erase the iPad should you decide to go that route.
    iOS: Understanding 'Erase All Content and Settings' - Support - Apple

  • Satellite A300 thinks button is held down and won't start up (long)

    Hey sorry this is so long but I would really love some help,
    Ok so I was just wondering if there is a way to fix this...
    I was on my Satellite A300 (just over a year old) last night playing the Left 4 Dead 2 Demo using the Stream network and all of a sudden in Online Co-op the Camera Assistant Window opened minamising Left 4 Dead 2.
    I thought this strange because I had closed the side popup bar for Camera Assistant on startup so that it wouldn't popup and do exactly what it did....
    So after being confused I just clicked back onto Left 4 Dead 2 and thought "I'll deal with that in a sec"... When Left 4 Dead 2 did maximise again, (it took a few moments where there was a black screen and about 1 second of audio looping), I couldn't physically play but I could watch the game in a special mode that lets you take a break and let AI take over for a while. Also the in game chat box was up.
    I was at first just trying to click the button to turn off AI control but the game wouldn't respond. Then my chat box's typing section started filling up with 'u's so I tried to get rid of them. All I could do was high-light them with my mouse and then more 'u's would replace them.
    After trying Alt+F4 for a while and Ctrl+Alt+Del with no responce except for the 'u's I decided the poor computer must be strained with Left 4 Dead open and Stream, Illistratror and the Camera open in the background so I pressed the power button (set to shut down on my computer) and waited...
    Left 4 Dead 2 closed, as did Camera Assistant I think... and then it kind of froze so I just held down the power button (sorry I know that probably wasn't the best move) and my laptop turned off...
    Well when I tried to turn it back on the Black "Toshiba Leading Innovation" screen pops up along with the little footer explaining what F2 and F12 do. After that the screen switches to the little blinking text bar thing (sorry I don't know what it's actually called...) but the bar flashes on and remains there for about 4-5 seconds and then flashes off and on again, although it seems slightly duller in colour) and then a single tone plays (from the computer even if earphones are plugged in) and yeah... I have to turn it back off...
    Remembering about the 'u's I assumed the computer was not happy that the 'u' button was being held down on startup so remembering that the fron of the keys are actually removable I (very carefully) removed the 'u' faceplate.It all looked 'normal' underneath... (I compared it to the 'y' button) and so pressed it a few times and re-placed the faceplate. Turned on the compter... Same thing happened...
    I then tried taking out the battery and then putting it back in to see if that would help... Again, the tone played... I took unpluged my iPod, Took out the CD, and removed the Memory Card to see if that would help... It didn't unfortunately.
    So next I tried turning on the computer whist pressing 3 keys (I thought it might cancel out the 'u' key) abd held down 'b+n+m'. The first time I did this Windows Boot Manager opened instead of the beeping. I only have Windows Vista so when I tried to continue by pressing 'enter' nothing happened... So I turned off the computer and tried again (this time with q+w+e as I thought maybe holding b+m starts Boot Manager). This time Windows Error Recovery displayed with the options; Safe Mode, Safe Mode with Networking, Safe Mode with Command Prompt and Start Windows Normally. Again Enter wouldn't work... And thats my sistuation so far...
    Please help if you can >: I'm scared if I take it to a Japanese Compute Person they'll wipe everything...
    Thankyou,
    Rochelle
    (again I am sorry this is so long but I thought people might wan't specifics...)

    hi Ellehcore,
    sure it is always the hardware.... nope!
    deinstall the webcam software and/or shutdown the webcam service
    this will prevent the software to show up in your game...
    but with this extended problems you should ask a servicepartner for assistance....
    or simply recover the system...

  • I did a factory reset on my late 2008 MacBook from a Snow Leopard disc. It installed fine, but as soon as I began to use the computer (safari) it froze. Couldn't even force quit. So I held down the power button to turn it off, and now it won't start up.

    I did a factory reset on my late 2008 MacBook from a Snow Leopard disc. It installed fine, but as soon as I began to use the computer (safari) it froze. Couldn't even force quit. So I held down the power button to turn it off, and now it won't start up. It goes to the grey Apple screen and just sits there loud as can be. Help! Please keep in mind I've not done anything like this before and am going to need a little hand-holding. Thanks in advance.

    Hi. Don't worry it's nothing serious. Insert the Instal Disc (Snow Leopard) and press the C button while turning on the computer. Once you see the desktop, go to Utility and choose Disk Utility. Select the Macintosh Partition on the left window pane and then click on Repair Disk and Repair Disk Permissions on the bottom right corner. Wait for both processes to finish. Click on the Apple icon (top left corner) and choose quit. Your computer should restart. See if it reboots normally. If not you can always reinstall the OS following the same steps. Good luck!

  • Machine mistakenly thinks mouse button is held down while dragging

    I have a bizarre, intermittent problem. Very occasionally, when I'm dragging files between folders, my computer thinks that the mouse button is still being held down even after I release it. As a result, I am constantly "carrying" the files around the screen with the mouse and I'm completely incapable of doing anything else since the machine thinks I'm mid-drag. As far as I can figure out, the only way to fix this is to reboot the machine. Extreme, I know, but I can't figure out any other way to get out of this state. This typically happens to me once or twice a week and I use my computer fairly heavily.
    So, has anyone else heard reports of this bizarre behavior before? Any solutions?
    I don't know if this matters, but I'm using a wireless mouse. However, plugging in a wired mouse while this is happening doesn't seem to be a solution.

    Have you checked your System Preferences? If not...
    Open System Preferences from your Application folder. Click: Keyboard&Mouse, and select the Mouse tab. At the bottom of that window change your Tracking, Scrolling and double clicking to see if that makes a difference.
    If the wireless is a Mighty Mouse, try cleaning it: http://support.apple.com/kb/HT1537
    Mice need cleaning periodically. Fingerprints, lotions, dust, and lint can cause problems.
    Clean the USB mouse as well.
    Carolyn

  • Kill the MouseEven.CLICK event when mouse is held down?

    I have been studying games on Facebook and am trying to emulate mouse event handling. For example in ChefVille you can click on objects and drag them around. But if you hold the mouse down you pan the entire game environment and when you release the mouse button a click is NOT registered on the object below the mouse. In my tinkering the CLICK event is triggered on the release of the mouse button no matter how long I keep the button depressed. How do I keep the CLICK event from firing if the mouse is held down for some period of time?

    I don't know that you can cancel a CLICK event in the middle of it happening (CLICK = MOUSE_DOWN followed by MOUSE_UP), but you can trigger a Timer on the MOUSE_DOWN event and use its event handler to set a boolean variable that your CLICK event handler function can make use of to decide whether or not to process a CLICK event.

  • HT4623 just updated my iPhone 4s to ios6, now my phone won't turn back on. The apple logo comes on and sits then shuts off. I have held down the home button and on/off switch several times to reset, but same problem persists.

    just updated my iPhone 4s to ios6, now my phone won't turn back on. The apple logo comes on and sits then shuts off. Then comes back on and just sits.I have held down the home button and on/off switch several times to reset, but same problem persists.

    Place iPhone on Wall Charger for at least 10 minutes. Then keep on charger and Reset, hold both home and power buttons until the iPhone begins to start, this can take about 20 seconds of holding both buttons while on charger. If still problem, open iTunes 10.7 on computer, connect iPhone to computer with USB Cable, hold both home and power buttons for about 20 seconds until iTunes recognizes iPhone in Recovery Mode, then click Restore button of iTunes. If still problem, try DFU Mode Restore, here are the steps. Open iTunes on computer. Connect iPhone to computer with USB cable. Hold both Home and Power buttons, after exactly 10 seconds release the Power Button, keep holding the Home button until iTunes recognizes iPhone in Recovery Mode, usually about 20 seconds time. If the iPhone screen is black, blank this is DFU Mode. Click the Restore button of iTunes. DFU Mode can be difficult to enter sometimes, just keep trying. DFU Mode is a black, blank screen with iTunes saying Recovery Mode. If still problem and there is Warranty or AppleCare make Genius reservation and take to Apple for resolution.

  • Touch Events: How can I check for a button being pressed while another button is being held down?

    Hello,
    I'm trying to check for a button being pressed while another is down through Touch.  In my case, I' m making a game and I need for a button to make the character jump.  However, when I hold down right, I notice that the jump button becomes somewhat unresponsive and I have to press it twice or more to get it to trigger, as opposed to just pressing the jump button by itself with nothing held down which works fine.  I'm testing this on my Motorola Droid 2.
    Here is some of my code that demonstrates text instead of my character moving around:
    package  {
         import flash.events.TouchEvent;
         import flash.ui.Multitouch;
         import flash.ui.MultitouchInputMode;
         public class Document extends MovieClip {
               Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
               private var controls:BottomBar;
               private var debugText:String;
               public function Document() {
                    addIngameGUI();
               private function addIngameGUI(){
                    controls = new BottomBar();
                    controls.y = stage.stageHeight - controls.height;
                    addChild(controls);
                    controls.aBtn.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.bBtn.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.leftArrow.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.rightArrow.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
             private function testBtns(event:TouchEvent){
                   debugText.text = event.target.name;
    What am I doing wrong?  Is there a better approach?
    Thank you in advance.

    Hello,
    I'm trying to check for a button being pressed while another is down through Touch.  In my case, I' m making a game and I need for a button to make the character jump.  However, when I hold down right, I notice that the jump button becomes somewhat unresponsive and I have to press it twice or more to get it to trigger, as opposed to just pressing the jump button by itself with nothing held down which works fine.  I'm testing this on my Motorola Droid 2.
    Here is some of my code that demonstrates text instead of my character moving around:
    package  {
         import flash.events.TouchEvent;
         import flash.ui.Multitouch;
         import flash.ui.MultitouchInputMode;
         public class Document extends MovieClip {
               Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
               private var controls:BottomBar;
               private var debugText:String;
               public function Document() {
                    addIngameGUI();
               private function addIngameGUI(){
                    controls = new BottomBar();
                    controls.y = stage.stageHeight - controls.height;
                    addChild(controls);
                    controls.aBtn.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.bBtn.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.leftArrow.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
                    controls.rightArrow.addEventListener(TouchEvent.TOUCH_BEGIN, testBtns);
             private function testBtns(event:TouchEvent){
                   debugText.text = event.target.name;
    What am I doing wrong?  Is there a better approach?
    Thank you in advance.

  • HT201412 ipod touch will not turn on even after ive held down the home and sleep buttons

    I have an ipod touch that just recently started to be unresponsive!  It had a good amount of battery left and then all of a sudden it turned off and now will not turn back on even after 30mins of charging.  no charging screen has appeared either.  ive held down both the home n sleep buttons for 10secs or more and still nothing has happened.  then i held down just the home button. still nothing and then i tried holding down the sleep/wake button for a couple seconds and still nothing has happened    are there any other ways of turning my ipod back on or did it **** the bed and i should get a new one?  thanks

    Try the remaining items here:
    iOS: Not responding or does not turn on

  • My macbook pro frooze, "spinning wheel of death", I tried to force quit.  When that failed I held down the power button.  Now I can't get by the white apple start up screen, the wheel just keeps spinning and nothing will happen...HELP!

    Again,
    My macbook pro just frooze while on-line.  I got the rainbow wheel spinnin and it wouldn't stop I tried to do a force quit and I was unable to do that.  So I held down the power button.  Now when I try to restart it I can't get by the while page with the apple symbol on it.  All I have is the grey circle spinning continuosly like it is working.  I tried a command S when I started it back up and checked the HD and rebooted, still can't get by the startup page.  Any suggestions?

    I'm having the same problem. I started an automatic upgrade that then got "stuck" for hours. I did a hard shut down and now all I get when I try to reboot is the spinning wheel. I haven't done a backup in 3 months and can't afford to lose everything in a reinstall. Any suggestions?

  • HT4623 I installed ios7 on my iPad 2 yesterday, this morning it wouldn't open the weather channel app. I thought maybe I should power it down. When I held down on the power button the screen went black and now it won't do anything. What do I do now?

    I installed ios7 on my iPad 2 yesterday, this morning it wouldn't open the weather channel app. I thought maybe I should power it down. When I held down on the power button the screen went black and now it won't do anything. What do I do now?

    Try a reset: Press and hold both Sleep/Wake and Home buttons until the Apple logo appears.

  • Clicking Causes mouse to be held down

    I've been having an odd glitch, sometimes when I click my mouse (I've tried with different mice) the mouse gets held down, and the only way to release it is to right click. This is especially bad trying to move files in Finder, as it means I can't let go of the file. Any resolutions?

    I'm assuming by the fact that you say you have tried different mice that the actual mouse is fine, it's just holding the click on the screen.
    First thing would be to check the Mouse settings under the System Preferences.
    JD

Maybe you are looking for

  • Display drivers for MacMini OS 10.4.8

    Hi, I just bought my first mac (mac mini) and I bought a Dell Ultrasharp 1907FP flat panel monitor. The VGA connector works fine and the screen is fine. However, the DVI cable gives either a black screen or a "hashed up" image (unusable). Looks like

  • Cannot get photoshop to print hi-def images

    For the last week I have not been able to find the print settings for hi-def printing in photoshop. They disappeared after the last software update. This problem appears on my Macbook and on my imac as well. Can any one advise? I have  Cs4 and it has

  • Last  1  sec  download  is  stuck  up,incomplete.

    error 100  is  coming  again  and  again..adobe  is  cut  off  frequently.last  i  sec  down  load  is  not   completing.

  • Product Availibility at Catalog Level

    Hi All Is there any way to display product availibility information at individual product level within Product Catalog? Thanks in Advance. Thanks Avi

  • I CAN'T CHAT...

    my ichat will login like it is supposed to, but when i double click on a buddyname to chat, their screen name will not appear on the top of the chat box, it just says 'CHAT'. When i type something in the box to send it says that i cannot chat and i h