Results 1 to 2 of 2
  1. #1
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Question Keyboard Events?

    Ok This is my java code

    JAVA CODE:

    package Samurai;
    import java.util.*;
    public class Samurai {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.println("To Explore your city Press Enter");

    cityexplore=(int) (Math.random()*10);

    while ((cityexplore%2)==1)
    {

    System.out.println(" You Came Across Nothing! Please Keep Exploring");

    System.out.println("To Explore your city Press Enter");

    cityexplore=(int) (Math.random()*10);


    }

    System.out.println("You came Across A MOBSTER");

    }

    }




    OK so how do i add a keyboard action to the program so the program continues only when the keyboard button is pressed i am not looking for any specific keyboard button any keyboard Key will do. Any Ideas ON HOW i can do this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Keyboard Events?

    In order to respond to a single key, you'll need to create a GUI such as a Swing GUI, or use a 3rd party console since the Java console only responds to entered Strings, not key presses.

Similar Threads

  1. Question on Java Graphics, KeyBoard Events and JFrame
    By loopsnhoops in forum New To Java
    Replies: 1
    Last Post: 02-10-2011, 03:12 AM
  2. Keyboard
    By UJJAL DHAR in forum New To Java
    Replies: 4
    Last Post: 01-29-2011, 02:26 PM
  3. getting each character from keyboard
    By Sreejesh25 in forum Advanced Java
    Replies: 6
    Last Post: 03-05-2010, 07:12 PM
  4. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 12:22 PM
  5. Help with keyboard events?
    By Bibendum in forum New To Java
    Replies: 2
    Last Post: 11-02-2007, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •