OptionPanes and keyboard inputs/exitting program (game quit)

Hi there,
Im implementing my game an assignment and Ive come across a problem that I cant seem to solve. Ive created an option pane that, in a win or lose situation, allows the user to restart or quit the game- the restarting is simple enough in that if the value of the option pane = 0 then it executes the resetGame method, the trouble comes with the quit option. At present it is linked to the resetGame but what I would really like is for it to have the same effect as pressing the 'S' key in the game (i.e. stop the game and display the main screen). Is there any way to do this? Is there like a quit to previous panel option, go back a screen, anything that can exit the game- as pressing s on the keyboard stops the game and goes back to the main screen.
The code in question is;
// make munchies move down the screen
for (int i = 0; i < NUM_MUNCHIES; i++) {
if (munchieDirection == 1){
munchieYPos[i] = munchieYPos[i] + munchieSpeed;
if (munchieYPos[i] > (boardHeight - munchieHeight)){   // if the munchies touch the bottom the create game end situation
gameLoseSound.play();
int value1 = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Lose", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
if (value1 == 0){
resetGame();} else {
resetGame();} //change to quit value
AND
// scoring and reset
if (score >= 5){
gameWinSound.play();
value = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Win", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
if (value == 0){
resetGame();} else {
resetGame();} //change to quit value
Any help on this matter would be much appreciated, as although my current method may suffice- its not 100% appropriate (in my opinion)

Got my main account working again now!
Still having trouble for this. Ive now completed the game- its all working, but I still havent solved the quit problem.
Is there anyway I can have the mouse click of the 'quit' button to flag up the same command as pressing the s key on the keyboard? Or is it possible to allow the quit button to allow the user to exit to the main menu?
PLEASE HELP! IM DESPERATE!
Thanx
Senor-cojones

Similar Messages

  • Using Firefox 3.6 after a few mouse click/ keyboard input the firefox window is no more active, mouse click and keyboard input is inactive ; then I click on the taskbar and the keyboard is active again during a few click then it stops again etc.

    Using Firefox 3.6 after a few mouse click/ keyboard input the firefox window is no more active, mouse click and keyboard input is inactive ;
    to solve it I click on the taskbar and the keyboard is active again during a few click then it does not work any more and I click again on the task bar etc.
    after several repetitions, I have to call the task manager alt+del+ctrl, then come back to the firefox window to be able to use keyboard and mouse again

    Attaching the picture for the tab shape I want...

  • Maple13, tiling wm and keyboard input

    Hi,
    I am using a tiling wm (musca). I installed maple and at first had the problem, that maple would show only a grey window.
    Using wmname and
    wmname LG3D
    I resolved the problem. Now the problem is, that the worksheets wont accept my keyboard input.
    Mouse/menus work. All dialogs also work with keyboard input.
    If I open a new worksheet, input works. But as soon as I switch worksheet it does not work anymore.
    Anyone an Idea what I could do?
    Thanks!
    PS: I already tried sun jre (from pacman) and openjdk6 by changing the maple startup file. It's always the same

    Depending in your window manager you may have the option to add a floating workspace. Try working there. If that doesn't solve the problem you can try runing an aditional floating window manager inside a Xnest or a Xephyr session. This has worked for me for some other problematic applications. For example try:
    Xephyr -ac -br -host-cursor -noreset -screen 1280x800 :1 &
    sleep 3
    twm -display :1
    this will initiate a new X session inside yours, which will be managed by twm. There you can run a terminal and of course maple. Maybe is a sub optimal workaround, but is the only alternative I have found.
    (Note that Xephyr is found in xorg-server-xephyr package and twm, well in xorg-twm )

  • Keyboard input makes program hang

    Hi,
    I'm writing a small web service client that takes 2 numbers, sends them to the service and gets the sum/division/product/substraction back as an answer.
    I'm finished with the C/S programming and all I want to do is for the user to input the numbers himself. I wrote the following lines, which should work just fine but for some reason the program hangs and when I type sthg, there's no input. Does anyone have an idea why?
    private static float getNum() throws IOException
         float a;
         String message;
         BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
         System.out.println("Enter a number (float): ");
         message = stdin.readLine();
         // the following line is never reached.
         System.out.println ("You entered: \"" + message + "\"");
         a = Float.parseFloat(message);
         return a;
    }Thanks.

    something else must be swallowing System.in ??
    how exactly are you running it?
    an Ant task still has access to System.in from my tests eg
    1)<?xml version="1.0" encoding="ISO-8859-1"?>
    <project default="all">
        <target name="all">
            <taskdef name="TestInput" classname="TestTask"/>
            <TestInput/>
        </target>
    </project>2)import java.io.*;
    import java.util.*;
    public class TestTask {
         public void execute() {
              try {
                   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                   List result = new ArrayList();
                   for(String line=""; ((line=br.readLine())!=null) && !line.trim().equalsIgnoreCase("quit"); ) {
                        result.add(line);
                   System.out.println("Got: "+result.size());
              } catch(Exception e) {
                   e.printStackTrace();
         public static void main(String[]arg) throws Exception {
              new TestTask().execute();
    }3) compile TestTask.java
    4) save xml above as test.xml in same directory as the TestTask.class file
    5) type "ant -buildfile test.xml"
    everything works as expected..
    you're not trying to access System.in via jsp or something??

  • Apple Wireless Mouse and Keyboard lose connection running games in Vista

    I installed Windows Vista Ultimate for playing games on my iMac. During games the *wireless Apple keyboard and wireless Might Mouse seem to loose connection at random intervals.* Looks like the bluetooth connection is lost (?, this is a guess). After 30 to 60 seconds the keyboard and mouse work again. This does not happen when using an USB mouse or keyboard.
    Any suggestions?
    All drivers are updated with driver suggestions form other posts.
    I'm running Windows Vista Ultimate on a 20inch 2,4GH iMac. Using Leopard Boot Camp. Wireless Apple Keyboard and wireless Might Mouse. All 2008 models.

    Found a post which said;
    always use a passkey for bluetooth devices in Vista using Boot Camp. Removed keyboard and mouse, reinstalled with passkey. Maybe this is helpfull.

  • Application Virtualization and Keyboard Input

    Hello,
    Today I have a need to leverage SendInput and it works just fine. However the issue really is having to swap between different windows, due to the requirement for SendInput.
    I got around this by using VM's and it works great.
    However, I was wondering if there is a better way to do this, without having to have total virtual machines.
    Is it possible to sandbox applications (virtualize) them, in a stand alone environment (meaning on a single machine), where-in each has it's own Message Input Subsystem?
    Something where I would be able to run Program A (+) Program B within a "virtualized" application architecture, and have Program B use SendInput to send data to the Program A "instance" that is inside the same application virtualization
    that B is in.
    I just want to get away from having to use "remote" desktops to Virtualized Machines to make this work
    It would look like this (well if this is possible that is)
    Machine A:
    Program A + Program B = "Instance #1". They run together
    Program A + Program B = "Instance #2". They run together
    From the actual desktop of Machine A, you could "see" Instance 1 and Instance 2 but using a Program C, communicate with Program B (on a per virtualized instance)
    Thus removing the overhead of total virtual machines, but with the ability to actually do "application virtualization".
    I really want to solve my problem on the Microsoft stack, not move to VMWare
    All my other options didn't work so now I moved to virtualization, which would be pretty sweet actually :-)
    Any help / thoughts would be great
    Thanks!!

    Regardless of how they communicate, the question is this.
    Is it possible to sandbox applications (virtualize) them, in a stand alone environment (meaning on a single machine), where-in each has it's own Message Input Subsystem?
    The rest was merely a description of potential architecture, based on the fact that Program A, needs to be communicated with by SendInput, which you cannot do without swapping focus.
    No differently than if it were VM's and I had say 3 remote desktops open on my local system. I can run programs within that "sandboxed" window and each has it's own Message Input Subsystem. I am trying to mimic, that with application virtualization,
    so that I can still have that ability, but without running VM's which use way too many resources.
    Any specific information on the actual question?
    Thanks and Happy Holidays!!

  • Firefox has a "jerky" response to scroll wheel and keyboard input

    Keyboard and mouse wheel response in Firefox is "jerky".
    In the case of keyboard response, sometimes I can type steadily and see characters appear, while other times several seconds may go by before I see the letters I type (for example, in filling out this form it happened three times to this point).
    The same is true of the scroll wheel on my Microsoft Intellimouse Explorer 2.0 mouse.
    At first I thought it was system-wide as I spend most of my computer time on my work computer, but I recently realized it's really only Firefox.
    I'd rather not do a total reset of Firefox if I can avoid it, as I still have a user chrome folder and a small handful of manually set about:config settings in addition to a few add-ons... unless I have certain knowledge that that will fix the issue(s).

    Have you disabled hardware acceleration?
    You might need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    Then perform these steps:
    *Click the orange Firefox button at the top left, then select the "Options" button, or, if there is no Firefox button at the top, go to Tools > Options.
    *In the Firefox options window click the ''Advanced'' tab, then select "General".
    *In the settings list, you should find the ''Use hardware acceleration when available'' checkbox. Uncheck this checkbox.
    *Now, restart Firefox and see if the problems persist.
    Additionally, please check for updates for your graphics driver by following the steps mentioned in the following Knowledge base articles:
    * [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    * [[Upgrade your graphics drivers to use hardware acceleration and WebGL]]

  • Enums and keyboard input

    I am currently enrolled in a java class. I am working on a project about enums and switch statements. I get what enums and switch statements are but what I don't get is the input/output. I need the user to be able to pick one of four anwsers.
    This might be something obvious but I am new to this.

    enum Command {SIT, HEEL, ROLL_OVER, BEG};
    public class EnumExample {
        public static void main(String[] args) {
            String[] inputs = {"SIT", "HEEL", "ROLL_OVER", "BEG"};
            for(String input : inputs) {
                Command cmd = Command.valueOf(input);
                System.out.println(cmd);
    }valueOf?

  • Keyboard input has stopped working in MS Word - Yosemite

    I made the mistake of upgrading to Yosemite in December.
    The latest issue is in MS Word (2011, version 14.3.6)
    When trying to switch between two Word documents, the keyboard input stopped working. I am using the built-in Mac keyboard. The trackpad still works, and keyboard input works in some programs (Safari), but it's impossible to type anything into Word. I've tried "Esc" in case some menu was selected, but to no avail.
    I've also had this problem in EndNote.
    Curious if anyone has a solution - and if you have tips for how to get Word to run faster in Yosemite, please post!
    Thanks ~

    There have been a couple reports of keyboard failures, mostly initial key presses. Mine initialy caused USB bus timeouts and startup problems and then failed completely. Call Apple or take the machine/keyboard back to a Apple store for a replacement.

  • Design question ... Remote control and keyboard

    Hey i am building a system that should support remote control input and keyboard input
    the system is a addons based any user could build any addon he wishes
    i have now two main input events types
    KeyEventand
    RemoteControlEventi wish to use only one type of event
    i am thinking of 2 options.
    1) Map
    RemteControlEventto
    KeyEventif this why is the best what happens i a situation that i mapped J key to the RECORD button
    how a specific addon should know that a RECORD operation is pressed or it's just a J button
    2) Write a new events that contains
    KeyEventactions and
    RemteControlEventactions
    thanks allot

    thanks for your replay
    i am sharing my thoughts with you ,cause i relay want to do it the best way.
    when i mention remote control i meant using a TV/VCR/MCE Remote Control.
    (i am usingJLIRC ( LIRC ) )
    and i have decided .
    i will listen to all keyboard event using "dispatchKeyEvent"
    and will map Remote control keys to keyboard keys
    here is another question to make sure i understand fully .
    the application that i am writing is an add-on based
    every programmer that will like to create an add-on
    will extend the "Screen" object for is main panel (Screen exnteds JPanel)
    so i was thinking when dispatchKeyEvent called i should call dispatchKeyEvent in the current displayed screen
    (if the screen dispatchKeyEvent returns false.
    the main dispatchKeyEvent should continue.
    case true the main dispatchKeyEvent will return true)
    then in the screen implementation the user can ask if this key is an Spacial Key
    if yes he can get the spacial key attached to this keyboard key
    i just wrote an example of how it's suppose to be
    public MP3PLayer implemants Screen {
      public boolean dispatchKeyEvent(KeyEvent e){
        boolean isSpeacial = RemoteComtrolKey.getInstance().isSpeacialKey(e.getKeyCode);
        if(isSpeacial){
            int mappedKey = RemoteComtrolKey.getInstance().getSpeacialKey(e.getKeycode());
            if(mappedKey  == RemoteComtrolKey.REC){
              //do the record
               return true;
        return false;
    }georgemc thank you very much

  • How to fix the mouse and keyboard freezing when installing Windows 7 on 27' iMac late 2013?

    Hi, I have a question for u guys who can solve this.
    I recently bought the new 27' iMac late 2013, and I installed some softwares and used it for few days.
    Before I bought this I used the 15' Macbook Pro Retina, I installed Windows 7 Home Premium 64 bit, and I used the Windows for gaming.
    So back to my question.
    So I bought the new iMac and I was tying to install Windows 7 Home Premium 64 bit (with the same CD).
    After dividing the partition, and other stuff, the iMac rebooted and I hold down the option (alt) key. I choose the Windows CD, and it said it is "getting ready to install Windows". I let it load, and the blue screen where you choose the language, time/location and keyboard input popped up. At the bottom right corner (at the same page), there is a button that said "Next (N)" which u need to click it to go to the next step. I was moving my mouse to click the button, but I realized that my mouse and keyboard was frozen. I tried both wireless and wired mouse and keyboard but they didn't work. There was nothing I could do. I hold the power button, (that was the only option) and tried my mouse and keyboard on Mac OS and it worked fine.
    I thought something went wrong in the CD so I bought the Windows 7 Ultimate 64 bit. The result was same. It frizzed again. (I just wast few hundred $)
    Latter my friend lend me his Windows 8.1 Pro 64 bit. I tried it, and it worked, it didn't freezed on Windows 8.
    The problem is I played Battlefield 4, Titan fall, and Watch Dogs, and Battlefield 4 multiplayer doesn't work on Windows 8.1. Even though when it works on Windows 8, I prefer using Windows 7.
    Dose anyone knows how to fix this freezing thing?
    My computer is:
    27' iMac late 2013 (bought it just few days ago)
    I did no upgrades when I bought it, except the graphic card.
    I bought the iMac in Korean Apple Store, and my Windows CD is in Korean, can that be a problem?
    Please leave a comment when u think u can solve my problem.

    See -> http://manuals.info.apple.com/MANUALS/1000/MA1636/en_US/boot_camp_install-setup_ 10.8.pdf.
    In addition to the Windows disc (or USB flash drive with the Windows installer) you'll need a 8GB+ flash drive.
    The referenced manual - on page 3, I think, gives you a run-down of what you'll need before you begin the installation. You may also want to post any further Boot Camp questions in the Boot Camp forum -> https://discussions.apple.com/community/windows_software/boot_camp.
    Good luck,
    Clinton

  • Keyboard input stopped working on Solaris 11 Live x86 Toshiba R835 Notebook

    I can boot, and keyboard input works for login, but does not work for xterm, terminal, Firefox, ... Mouse works for gparted and apps. It did work for 8 hrs but stopped. Any suggestions ?

    brebs wrote:
    (EE) Error loading keymap /tmp/server-0.xkm
    I would be googling for that. E.g. see thread.
    So did you update xkeyboard-config? It's tedious that you haven't had the sense yet to list which packages got updated, along with version numbers.
    It's nice to see you enter here, brebs!
    A few things have happened:
    I just noticed that the file '/etc/X11/xinit/xinitrc' isn't present at all! It was present when I posted the thread (I think). So X didn't even start. I had to create .xinitrc in my home directory with single like 'exec xterm'. X started fine but keyboard still didn't work.
    Out of nowhere, I thought of using nouveau drivers instead of Nvidia drivers. So I went ahead and switched to nouveau and bam - keyboard is working. Enabled GDM and keyboard is still working. I still would like know what went wrong with Nvidia - for educational purposes.
    What more details should I provide? I'd like to have Nvidia drivers back.
    Last edited by akshay2000 (2013-02-25 16:17:07)

  • My safari screen suddenly fills my entire screen, and there is no right hand corner button to push to manually shrink it. What to do? I can never even exit the program without quitting it.

    My screen when I am using Safari suddenly fills my entire screen, and there is no right hand corner button to push to manually shrink it. What to do? I can never even exit the program without quitting it.This has happened only within the last two days.

    Try changing the screen resolution.
    Go to Apple Menu / System Preferences / Displays.
    Change the resolution. Whatever numbers are shown, e.g. 1280 x 960, select a larger one. The larger the number, in the resolution the smaller the display on the screen. You can keep changing this till you find the resolution that suits you.

  • OSX/SL 10.6.8 all window apps lose keyboard input; mouse and cmd-N work for spaces

    Input suddenly stops going to all applications, from MacBook Pro and wireless keyboards, and from "Show Keyboard viewer" (OSX 10.6.8 'Snow Leopard', MacBook Pro). Though the OSX Keyboard Viewer shows the keys onscreen as they are pressed on the MacBook and wireless keyboards. 'Spaces' responds to cmd-N commands, but no input is possible to any running or newly-started 3rd party or Apple-provided application. Killing off applications one by one doesn't recover keyboard input ability;  a complete reboot appears necessary to restore the ability to key input into applications. This happens repeatedly, yet never registers as an OS/X 'crash' because 'Force Quit'ting applications and restarting is still possible using only the magic mouse or trackpad.   No data  whether only logging out and back in would correct the apparent input-focus disconnect of all applications with the window manager. There may be some way to restart the window manager by using the mouse to open up new apps and/or cut and paste characters ( including a carriage return ) or cut and paste entire saved typed commands into a terminal window.

    Do a backup, using either Time Machine or a cloning program, to ensure files/data can be recovered. Two backups are better than one.
    Try setting up another admin user account to see if the same problem continues. If Back-to-My Mac is selected in System Preferences, the Guest account will not work. The intent is to see if it is specific to one account or a system wide problem. This account can be deleted later.
    Isolating an issue by using another user account
    If the problem is still there, try booting into the Safe Mode using your normal account.  Disconnect all peripherals except those needed for the test. Shut down the computer and then power it back up after waiting 10 seconds. Immediately after hearing the startup chime, hold down the shift key and continue to hold it until the gray Apple icon and a progress bar appear. The boot up is significantly slower than normal. This will reset some caches, forces a directory check, and disables all startup and login items, among other things. When you reboot normally, the initial reboot may be slower than normal. If the system operates normally, there may be 3rd party applications which are causing a problem. Try deleting/disabling the third party applications after a restart by using the application un-installer. For each disable/delete, you will need to restart if you don't do them all at once.
    Safe Mode - About
    Safe Mode

  • Omputcer has been installed with a German programme, originally programmed in English with English keyboard. The keys are the same as before but the keyboard is now programmed in German and I cannot find the way to enter @. How can I do it?

    My computer has been installed with a German programme, originally programmed in English with English keyboard. The keys are the same as before but the keyboard is now programmed in German and I cannot find the way to enter @. How can I do it?

    Hello r555,
    Thank you for being a My Best Buy member, and thank you for visiting our forum.  I am very sorry to hear that it has not always been easy for you to receive your Gamers Club Unlocked bonus when trading in games.  I'll be happy to talk to you about your experience.
    I get the impression you are quite familiar with the trade-in process and how the bonus is applied, and it is disappointing to hear that a store associate wouldn't attempt to complete that process.  I will be sending you a private message so we can get some more specific information regarding which store you were at as well as the trade in question where you did not receive the bonus.  Please watch for a message from me shortly.
    Sincerely,
    Mike|Social Media Specialist | Best Buy® Corporate
     Private Message

Maybe you are looking for

  • Can I use Apple Remote desktop to connect over the internet?

    I would like to use Apple Remote Desktop to connect back to my MacPro desktop at home while I am on my Macbook Air at work.  Will I need a static IP from my service provider to do it.

  • What's a good level to record voiceover?

    Hi, I'm completely new to audio production, and need to record a voiceover. I've got my mic hooked up, and am getting a level of some sort. What I'm wondering is, what's a good level? I mean, I understand that the closer to 0 dB I can get, the better

  • No emails in my gmail inbox

    i have created my gmail account on my Nokia C5, all my other folders have mail in them apart from my inbox. Could someone please assist me on what to do as all my other email accounts are working fine.

  • Servlet plus mysql problem

    Well... Using Tomcat 557 and MySQL 411 I have a problem. I load a Driver (MySQL Connector/J) and create a connection object in servlet's init procedure. All woks fine. I stop Mysql and reload the servlet, nothing can be seen on a browser window - as

  • [Solved] Odd USB mouse behaviour on boot, needs replug to work

    Hey everyone, this post may seem similiar to the others that have been popping up about USB mice not working on boot, but I still couldn't fix my problem using those threads and I have a suspicion that mine's cause is different. Anyway: the mouse see