How to use addKeyListener in a program running using command prompt

Does anyone have any idea how to add the addKeyListener to a program running using command prompt.
Let me explain how the program run.
The program is start and accept call from other program. But from time to time, I need to issue some command by pressing the keyboard, let say, ESC is closed the program, F1 is showing the stated. F2.... (This is all need to run in the command prompt windows)
My problem is this program does not have any gui interface, so how can it be added?
i do it this way
public void key(){          
addKeyListener(this);
But it have compile error.
mainServerImpl.java:87: cannot resolve symbol
symbol : method addKeyListener (mainServerImpl)
location: class mainServerImpl
addKeyListener(this);
I did implement KeyListener. But just don't know how to solve this error.
can anyone tell me how to solve it or point me a source that can help.
Thank in advance!
Regards,
Tai Tan

Write your own Thread, to do this:
public class KeyThread extends Thread {
   public void run {
      while(true) {
         int i = System.in.read();
         if(i == 123) {
            break; // to stop the thread
// in your main:
Thread keyThread = new KeyThread();
keyThread.start(); // calls run() of the thread

Similar Messages

  • How java runs in command prompt and why java runs on it

    how java runs in command prompt and why java runs on it

    command prompt was used before the development of IDEs like RAD,eclipse etc.
    its still used for better understanding of the compilation and errors.
    type the java file and save the file(source file) in the bin folder of ur jdk environment with extension .java. the source file must be the one that has the main method declared.
    in the cmd prompt screen , set the path of bin folder.
    eg:C:/program files/jdk(some version)/bin/...
    for compilation,type:
    javac (source file_name).java and press enter
    for running the file:
    java source file_name

  • How to run a command prompt " command " through java code

    hi all,
    There is a command
    "java -jar selenium-server.jar -interactive"
    which i am running through command prompt after going to D:\MyFolder\Examples .
    i want to execute this command using java code .please help

    This has already been answered in your other two threads on this topic - http://forum.java.sun.com/thread.jspa?threadID=5221221&messageID=9898287#9898287 and http://forum.java.sun.com/thread.jspa?threadID=5221223&messageID=9898290#9898290.
    For some reason you don't want to read the reference that tells you exactly how to do what you want and how to avoid the pitfalls - http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .

  • How to save a fmb in the database thru command prompt?

    Hi,
    How to save a fmb in the database thru command prompt?
    I have around 25 fmb template files which needs to be saved in the database.Every time when we apply the new dump , we need to resave the templates in the database to compile other application related fmb files.Its a time consuming process and Monotonous for me. Is there anyway to save the forms in the database thru batch file, so that just I have to execute the batch file every time.
    Expecting your earliest feedback.
    Thanks & Regards,
    G.S -
    [email protected] / [email protected]

    Hi Frank,
    Thanks for your feeback.
    I am using forms6i.Basically our application was migrated from 4.5 to 6i two years back. Due to some reasons our technical team members are insisting us to store the template FMB's into the database to do the coding activities at site.
    Once in a month we are receiving the live dump for test database.Hence the problem.
    Please suggest the easiest way to store the template FMBs in the database.
    Thanks & Regards,
    G.S

  • How can we write the code for opening the command prompt and closing the

    how can we write the code in java for opening the command prompt and closing the cmd prompt from eclipse (cmd prompt should close when click on the turminate button in eclipse)

    rakeshsikha wrote:
    how can we write the code for opening the command prompt and closing theBy typing in Eclipse (which you seemingly have)?

  • Is it possible to run a command prompt(or DOS Command) through flash and run a Activex(.OCX) file from flash

    Hi all
        Is it possible to run a command prompt(or DOS Command) through flash.If it possible please guide me to do that throug AS 3.0.
       and
    Is it Possible to run a activex (.OCX) file from flash. If it is so please guide me the way to do it
    Thanks and Advance
    Sankar.M.S

    Or create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).

  • Is it possible to run a command prompt(or DOS Command)  and Activex File(.OCX)

    Hi all
    Is it possible to run a command prompt(or DOS Command) through flash.If it possible please guide me to do that throug as 2.0. and is it possible to run a Activex File(.OCX) through flash.
    Thanks and Regards
    Sankar.M.S

    Or create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).

  • Any Ideas How I can Make this Formating Program Run Faster?

    I'm using LabView 8.0.1 to extract columns and rows from MS Excel to format to a specific format which can be read into a software program we use in-house.
    The software program requires a specific header which declares variables, etc and also fomats the extracted data in an arcane way.
    Due to an error in the software program we use, the file format that has to be read in is not uniform and has the first line containing  two point sets (see attached file for an idea of what I am talking about). Any other format will not be read by the program.
    This introduced some problems, and finally, I ended up with an highly inefficient program. It runs, but is relatively slow.
    The programs, the input excel file and output file are given for example. 
    A couple of notes on the files:
    1) The file type used as input is just an excel file which has been saved in space-delimited format.
    2)  To speed up the process,I  permitted the formating of only 2 variable types (x, y, z, variable 1, variable 2). I haven't gotten to adding more variables. Ideally, I would like to count the number of columns on the excel file, read the headers and then write the output file automatically with all the variable names.
    3) I used sequenced loops in the vi, which is probably not the best way to do this. I am guessing that I can interweave all the numbers into one large array before writing --- but have no idea how I can accomplish that.
    The output file extension is actually .fvp. I've renamed it in order to upload the file.
    Any help/suggests would be greatly appreciated!!
    ~Janak
    Files are attached.
    Attachments:
    ParticlePathExport-SlowVi.vi ‏65 KB
    Input_File_Example.txt ‏1 KB
    Output_File_Example.txt ‏1 KB

    Use the Format Into String Function instead of the large concatenation.  Most of your inputs are constants, so they could be put into the Format string of that function.  It looks like you have only 2 truly variable string inputs, so they would show up as %s in the format string.
    So your format string would be something like this (\codes turned on)  (VI is LV 8.5)
    Message Edited by Ravens Fan on 09-28-2007 05:05 PM
    Attachments:
    Example_BD.png ‏20 KB
    Untitled 2.vi ‏16 KB

  • How do I find out what program is using what port?

    Hi
    I would like to know what program is using what port? I would also like to know how to close a port. I did a port scan and these ports were open:
    Open TCP Port: 1033 netinfo-local
    Open TCP Port: 20221
    Open TCP Port: 20222 ipulse-ics
    Open TCP Port: 20223
    Open TCP Port: 20224
    Open TCP Port: 20225
    Open TCP Port: 20226
    Open TCP Port: 20227
    Open TCP Port: 20228
    Open TCP Port: 47807
    I am using netbarrier on my computer.
    Thank you for your help.
    iBook G4   Mac OS X (10.4.8)  

    This document may help with your first question:
    "Well known" TCP and UDP ports used by Apple Software Products
    This IANA listing of the port numbers is also useful, if more detailed.
    You can use the Sharing tab of System Preferences to configure the firewall to block all ports except for those specified; you can use the command-line ipfw utility to set up more detailed firewall configurations.
    Matt

  • Program running under UAC prompt hides mapped drives

    I have a user on Windows 7 with a non-admin account who runs a program that pops up the UAC. She clicks yes and the program runs. However, since the UAC was involved, it is running with a different token than what she logged into the computer with.
    This means that the program doesn't see her mapped drives when doing a File | Open. She has to navigate to the data folder on the server via Network. Needless to say this is cumbersome and inefficient.
    What can I do so that the program sees her mapped drives? I don't know of a way to get rid of the UAC except to turn off UAC which I do not want to do.
    Jonathan

    Hi Jonathan,
    I hope this might help you.
    Running Your App with Administrator Privileges
    There are times that you may need administrator privileges for an application. You may write code that directly interacts with a piece of hardware or an app that sets machine-wide settings in HKLM. When possible, you should design your apps to limit the
    need for admin privileges to narrow sections of code, or communicate to an application started with full administrator privileges. Aside from MSI-based elevation, there are two ways to create processes with a user's full administrator token. The Application
    Information Service (AIS) will check during process creation and during the creation of a COM object using the CoCreateAsAdmin moniker to see if the
    binaries require administrator privilege. It is important to note that the elevation occurs at the time of process creation. The process token never has privileges or group membership added during run time, only when it is
    created.
    More information:
    Teach Your Apps To Play Nicely With Windows Vista User Account Control
    http://msdn.microsoft.com/en-us/magazine/cc163486.aspx#S7
    Making Your Application UAC Aware
    http://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware
    Thanks.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Error while running the SAP JCO java program running via command line

    Hi,
        We are facing an issue while using SAP JCO. When i try to run the sample program using RAD 8.0 ( IBM IDE tool For Java Development) its working fine.
    The same sample program if i try to run using command line, Then its giving below exception message.
    Exception in thread "main" java.lang.NoClassDefFoundError: Integration
    NOTE: I have configured proper sapjco jar & Dll files path in class path settings in my batch file.

    Hi,
    class loader can't find class definition during runtime but it could find it during compilation. So the problem is with your classpath. Does your classpath point to file with class Integration? Check this [blog|http://javarevisited.blogspot.com.au/2011/06/noclassdeffounderror-exception-in.html].
    Cheers
    Added reference to blog.

  • Newbie: how to temporary results and handle sessions running UNIX commands?

    Hello,
    I have just asked a question concerning launching UNIX commands using Java classes, see thread "_https://forums.oracle.com/forums/thread.jspa?threadID=2429211&tstart=0_".
    I have followed the mentioned advises (using "bash","-c" parameters) but now I have stumbled into other issues:
    My intention is to write a UNIX class, that can handle UNIX commands, in order to be used in other Java programs, so that the following example becomes possible:
    UNIX.launch("cd /var/core");
    UNIX.launch("rm obsolete_core_file");
    UNIX.launch("sqlplus <Oracle_database>");
    UNIX.launch("select * from cat;");Unfortunately I have stumbled into a strange behaviour: until now, I have created the UNIX class as a single class, containing a "main" method. When I launch the following commands:
    java UNIX "cd /var/core";
    java UNIX "rm obsolete_core_file"I have the problem that the "cd /var/core" command is executed while UNIX class is running, but afterwards I jump back to my current directory:
    pwd => current directory
    java UNIX "cd /var/core" (this is executed, e.g. verifying "ls" output)
    pwd => current directoryI would like to have:
    pwd => current directory
    java UNIX "cd /var/core"
    pwd => /var/coreOne other thing is the handling of sessions: until now, when I launch following commands:
    UNIX.launch("sqlplus <Oracle_database>");
    UNIX.launch("select * from cat;");Then I get into a "sqlplus" session, but afterwards my Telnet session hangs. Is there a way to see that I have fallen into a session, and handle it? (Exit, launch internal session (SQL-plus) command, ...)
    Thanks again
    Dominique

    scampsd wrote:
    Hello,
    I have just asked a question concerning launching UNIX commands using Java classes, see thread "_https://forums.oracle.com/forums/thread.jspa?threadID=2429211&tstart=0_".
    I have followed the mentioned advises (using "bash","-c" parameters) but now I have stumbled into other issues:
    My intention is to write a UNIX class, that can handle UNIX commands, in order to be used in other Java programs, so that the following example becomes possible:
    UNIX.launch("cd /var/core");
    UNIX.launch("rm obsolete_core_file");
    UNIX.launch("sqlplus <Oracle_database>");
    UNIX.launch("select * from cat;");Unfortunately I have stumbled into a strange behaviour: until now, I have created the UNIX class as a single class, containing a "main" method. When I launch the following commands:
    java UNIX "cd /var/core";
    java UNIX "rm obsolete_core_file"I have the problem that the "cd /var/core" command is executed while UNIX class is running, but afterwards I jump back to my current directory:
    pwd => current directory
    java UNIX "cd /var/core" (this is executed, e.g. verifying "ls" output)
    pwd => current directoryI would like to have:
    pwd => current directory
    java UNIX "cd /var/core"
    pwd => /var/coreOne other thing is the handling of sessions: until now, when I launch following commands:
    UNIX.launch("sqlplus <Oracle_database>");
    UNIX.launch("select * from cat;");Then I get into a "sqlplus" session, but afterwards my Telnet session hangs. Is there a way to see that I have fallen into a session, and handle it? (Exit, launch internal session (SQL-plus) command, ...)
    Thanks again
    DominiqueWhy not just use plain java File I/O http://docs.oracle.com/javase/tutorial/essential/io/fileio.html and JDBC http://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html for fulfilling your requirements?
    Edited by: maheshguruswamy on Aug 20, 2012 10:32 AM

  • Program runs at command line, but has "Error in Workspace" in Eclipse

    This code compiles and runs in Eclipse, but before it runs it show the message that I have "Errors In Workspace". The source code does not show any errors in Eclipse, so I copied the code into DOS, compiled it, and it runs fine. Any ideas why Eclipse is giving a problem?
    (I posted the code here: [http://shelbyandlesley.com/flash/import_javax.pdf] )

    kajbj wrote:
    Errors in workspace doesn't sound like errors in the java code. What happens if you create a new workspace?Thanks for pointing me in the right direction. I did not realize that "Workspace" encompassed the whole package. I had an error in another class in the same package and once I fixed that error, the program runs fine.
    Edited by: Shelby on Apr 10, 2008 3:19 PM

  • Run in command prompt

    Hi,
    I have a java application project which has a package with my code and one more package generated by web proxy.How can i run this in command prompt.
    Or how can i create an executable jar with all required libraries and everything.

    It's not recognizing javac, probably because you didn't set the PATH.
    PATH="C:\Program Files\Java\jdk1.5.0_12\bin"Adjust it to the location of your bin folder.

  • Runtime.exec() I need to run a command prompt command from java.

    the code i have that doesn't seem to work is:
    String driveloc = System.getProperty("user.dir").substring( 0, 1 );
            String path = jTextFieldPath.getText();
            String path2 = jTextFieldPath.getText().substring(0, jTextFieldPath.getText().length()-3) + "lst";
            String[] cmd = { "cmd.exe", "/" + driveloc, "ASMtools\\AS11 " + path + " -L >" + path2};
            txt_mf.append( cmd[3] );
            try {
                Process np = Runtime.getRuntime().exec( cmd );
            catch( java.io.IOException ioe) {
                //error
            }jTextFieldPath.getText() contains the path of the file saved by my program.
    the line of code i am trying to run is:
    AS11 FILE1 -L FILE2this line compiles the asm file and converts it to a lst creating an s19 file in the process. AS11 is an exe that aids the command prompt much like javac.
    If you could help me figure this out it would be great.
    Thanks in advance,
    -Juke

    String driveloc =
    System.getProperty("user.dir").substring( 0, 1 );
    String[] cmd = { "cmd.exe", "/" + driveloc,
      "ASMtools\\AS11 " + path + " -L >" + path2};Are you sure you want to invoke cmd.exe with the switch /c or /d or whatever depending on System.getProperty("user.dir") ?
    Starts a new instance of the Windows 2000 command interpreter
    CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
        [[S] [C | /K] string]
    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    /S      Modifies the treatment of string after /C or /K (see below)
    /Q      Turns echo off
    /D      Disable execution of AutoRun commands from registry (see below)
    /A      Causes the output of internal commands to a pipe or file to be ANSI
    /U      Causes the output of internal commands to a pipe or file to be
            Unicode
    /T:fg   Sets the foreground/background colors (see COLOR /? for more info)
    /E:ON   Enable command extensions (see below)
    /E:OFF  Disable command extensions (see below)
    /F:ON   Enable file and directory name completion characters (see below)
    /F:OFF  Disable file and directory name completion characters (see below)
    /V:ON   Enable delayed environment variable expansion using c as the
            delimiter. For example, /V:ON would allow !var! to expand the
            variable var at execution time.  The var syntax expands variables
            at input time, which is quite a different thing when inside of a FOR
            loop.
    /V:OFF  Disable delayed environment expansion.

Maybe you are looking for

  • Using dtrace how can we get the functionality of prstat ,vmstat

    Hi, I would like to know what probes can be used to generate a dtrace (.d) script which could produce the output of prstat,vmstat etc.I cannot use these commands at the command prompt directly to know my system's behavior.Can any one here help me out

  • I lost all my purchased songs when my hard drive.  Can I get another copy from Apple?

    I lost all my purchased songs when my hard drive.  Can I get another copy from Apple?

  • Flash Plug-In Failure

    A little over a month ago, I updated to the latest version of Flash Player and it suddenly stopped working properly. Some items work, some give me 'plug in failure'. Works: Netflix, about 50% of YouTube videos Doesn't work: the other 50% of YouTube v

  • Dashboard widgets won't install

    When I download a widget and click 'install' nothing happens. I have tried to move the widget directly to my home/library/widgets folder, but apparently I don't have one. When I tried to create this folder, I was told "The item cannot be created beca

  • Recreation of a Org Unit...

    Hi Gurus, If a Org. unit is deleted from org structure...can we recreate the same org unit.... any input is welcome. Thanks IS