How to use another java program to stop this running prpgram???

Dear Sir:
I have following code and I run it success,
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
public class CertainAndRepeatTime{
  public static void main(String[] args) throws IOException{
    int delay = 1;
    Timer timer = new Timer();
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
          System.out.println("Hello World Timer");
    System.out.println("What do you want (Certain time or Repeat time)?");
    System.out.print("Please enter \'C\' or \'R\' for that: ");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String ans = in.readLine();
    System.out.print("Please enter  ans=" + ans  + " IsTrue=  " + (ans.equals("R") || ans.equals("r")) +"\n");
    if (ans.equals("C") || ans.equals("c")){
      //System.out.println("This line is printed only once start...");
      timer.schedule(new TimerTask(){
        public void run(){
          System.out.println("This line is printed only once.");
      },delay,1);
    else if(ans.equals("r") || ans.equals("R")){
        timer.scheduleAtFixedRate(new TimerTask(){
          public void run(){
            System.out.println("This line is printed repeatedly.");
        },delay, 1000);
      while(true){
           //System.out.println("Charles print This line is printed repeatedly.");          
      } //This will make your main thread hang.
    else{
      System.out.println("Invalid Entry.");
      System.exit(0);
    System.exit(0);
}But I hope to use another java program to stop it when it is running instead of pressing CRTL + C to stop it.
How to do it??
Any example??
Thanks a lot!!

Sorry, I think i did not express cearly. It is my fault.
I re-write my requirements again:
I have
Class AAA1.java,
Class AAA2.java,
Class AAA3.java,
Class AAA20.java...
etc
they all look like the program I posted first time,, once executed, they will run for ever, and they will be stopped until I press CRTL + C;
Now I hope to use another java class StopProgram.java to stop them 1 by 1 or at once instead of pressing CRTL + C;
In this case, how to code this StopProgram.java ??
Thanks

Similar Messages

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How to find out jre version installed ,using a java program?

    Hello,
    Is there any way to find out the installed JRE version using a java program ?
    The requirement is as follows:
    There is a html page with 4 steps to install a software. each step is a link, which upon clicking does its work.
    the first step is to install jre 1.4.2_11 if its not installed in the system. But how can i find out whether jre 1.4.2_11 is installed or not ?
    Thanks in advance

    For the hell of it... here is a list of properties you can query:
    java.version Java Runtime Environment version
    java.vendor Java Runtime Environment vendor
    java.vendor.url Java vendor URL
    java.home Java installation directory
    java.vm.specification.version Java Virtual Machine specification version
    java.vm.specification.vendor Java Virtual Machine specification vendor
    java.vm.specification.name Java Virtual Machine specification name
    java.vm.version Java Virtual Machine implementation version
    java.vm.vendor Java Virtual Machine implementation vendor
    java.vm.name Java Virtual Machine implementation name
    java.specification.version Java Runtime Environment specification version
    java.specification.vendor Java Runtime Environment specification vendor
    java.specification.name Java Runtime Environment specification name
    java.class.version Java class format version number
    java.class.path Java class path
    java.library.path List of paths to search when loading libraries
    java.io.tmpdir Default temp file path
    java.compiler Name of JIT compiler to use
    java.ext.dirs Path of extension directory or directories
    os.name Operating system name
    os.arch Operating system architecture
    os.version Operating system version
    file.separator File separator ("/" on UNIX)
    path.separator Path separator (":" on UNIX)
    line.separator Line separator ("\n" on UNIX)
    user.name User's account name
    user.home User's home directory
    user.dir User's current working directory

  • How to find out internet explorer version ,using a java program?

    How to find out internet explorer version ,using a java program?

    Browser version from java?....you must be referring it from some web application....rite?
    You can read the User-Agent header using request.getUserAgent() or request.getHeader("User-Agent") in your jsp or servlet.
    for more details pls refer:
    http://www.jguru.com/jguru/faq/view.jsp?EID=12253

  • Can we run EXE file/ Another Java Program from Java Application? How?

    Can we run EXE file and another java program from java application?
    Thanks in advance

    Example running adobe acrobat
    String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
    Runtime rn = Runtime.getRuntime();
    Process process = rn.exec(command);
    process.waitFor();rykk

  • How to find out internet version ,using a java program?

    Can any one send javacode to find out the internet version ,using a java program?

    i mean internet explorer version
    Edited by: mvasu on Feb 20, 2008 2:04 AM

  • How To Get A Java Program To Initiate Auto Dial in Windows???

    I have a Java program that opens a connection to a server (another Java program) using sockets and streams. On some windows machines (various versions) with auto dial enabled the connection is made without human intervention. However on some windows machines (even same as others) the autodial doesn't work and all I receive is NoRouteToHostExceptions.
    What I need is some way of initiating the autodial from within Java explicilty rather than assuming that the OS will do it when a request is made to a remote IP address.
    I emplore anyone with some knowledge of this to provide assistance as I am going nuts trying to solve this problems.

    A long time ago I figured out how to create, find, and manipulate items in the DialUp Networking using an InstallShield program. I am sorry I can't remember specifics (I wouldn't have even replied except no one else has either...) but I remember that I did a LOT of hunting on Microsoft's website for how to do this on the various platforms of the day (Win95, Win98, NT4.0).
    I imagine that in order to accomplish this from java, you will probably need to find the system-specific commands (at Microsoft) and exec them from your java program.
    /Mel

  • Is there any way to check another Java program running status?

    HI. I want to write a Java program on hand-set but my program seems needs lots of resources and if there is another Java program running on the same hand-set simultaneously, my program will slow down. So, I want to check if there is another Java program is running on the hand-set, my program will show a message to user reminding user to close another program first.
    Is there any way to do so?

    On most recent devices, the application is not terminated but paused by using phone functions, and can be reactivated from the aplication management software. The javax.microedition.midlet package documentation is quite specific, if a tad obscure, about the MIDlet lifecycle and the role of the MIDelt methods vis-a-vis the AMS.
    {color:#0000ff}http://java.sun.com/javame/reference/apis/jsr037/javax/microedition/midlet/package-summary.html{color}
    Parenthetically, I've never been able to figure out how resumeApp should be used, nor have I seen this method invoked in any of the samples that come with the WTK, but I haven't gone through all of them.
    I believe the still-in-progress MIDP3 will make it possible to have MIDlets that share the screen with native apps and which can be minimized and restored.
    db

  • How to launch a java program in a new process

    Hello !
    II have a Java program, in which I want to carry out another Java program but in a new process, this new program requiring the definition of constants to the launching of the JVM.
    How can I do it ?
    Tank you for your help.

    Use
    Runtime.getRuntime().exec( cmd ); //where cmd is command for run java program.
    cmd may be "java test".
    You may also try using jnlp to run you java program in a new process.
    cmd will be "cmd /c \"javaws " + jnlpFile + "\"";

  • Opening a project in Eclipse by using a java program from outside..

    Hi friends,
    I have a java program which will open the Eclipse editor..now i want to open a file , in a specifeid path, in that eclipse. I completed opening the eclipse editor and also i m fetching the file which in a particular path..my problem is i couldnt open that file in eclipse by using my java program..
    i donno how to open a particulat file or proj in the eclipse from outside java prog.
    thanks,
    Krishna

    Try this:
    Error "This project contained a sequence that could not be opened" 

  • How to make a Java program that recognises a function of two variables...

    How to make a Java program that recognises a function of two variables to assign values to that?
    First I will give an example and then do the question.
    Ex1.
    We have any function, eg.y = x ^ 2 + 1 (read 'y' equals 'x' high to the square), a function of the second degree.
    To build the graph of this function attach values to 'x' to find the values of 'y'
    And thus mount the pair ordered (x, y) which represents a point on the Cartesian plane.
    Assigning values to 'x' 'we can build up a table that gives us the pairs ordered:
    We can use any numbers, but arfer interval [-3.3]
    X | y = x ^ 2 + 1
    -3 | Y = (-3) ^ 2 +1 = 10
    -2 | Y = (-2) ^ 2 +1 = 5
    -1 | Y = (-1) ^ 2 +1 = 2
    0 | y = (0) ^ 2 +1 = 1
    1 | y = (1) ^ 2 +1 = 2
    2 | y = (2) ^ 2 +1 = 5
    3 | y = (3) ^ 2 +1 = 10
    We then ordered the pairs:
    (-3.10), (-2.5); (-1.2), (0,1), (1,2), (2,5), (3,10)
    Tabem that can be represented by a table:
    X | y
    -3 | Y = 10
    -2 | Y = 5
    -1 | Y = 2
    0 | y = 1
    1 | y = 2
    2 | y = 5
    3 | y = 10
    Now I begin to explain my doubts.
    See this program:
    Ex2
    * To change this template, choose Tools | Templates
    * And open the template in the editor.
    Encontrando_o_valor_de_y package;
    * @ Author des Soldat Gottes
    Import javax.swing.JOptionPane;
    Public class (Main
    * @ Param args the command line arguments
    Public static void main (String [] args) (
    Int x, y;
    String x1;
    X1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',"); / / receives a value for the function y = x + 1
    X = Integer.parseInt (x1); / / tranforma String in int
    Y = x + 1; / / receives the value of 'x' and calculates' y '
    JOptionPane.showMessageDialog (null, "The value of 'y' is: \ t \ t" + y);
    / / Displays the value of 'y'
    System.exit (0);
    We see that the program receives above a value for 'x' and replaces the function contained in the program, y = x + 1, and so is the value of the variable 'y'.
    In: x1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',");
    The entry is a number and that number is assigned aa ja existing function in the (y = x + 1).
    The question is: would it be possible to come to a function?
    Ex: the program ask: DIGITE THE FUNCTION?
    The USUARIO DIGITARIA A FUNCTION ANY, TYPE: y = x ^ 2 +1
    The program would recognize the function and give numerical values to that function as Ex1, at the beginning of this text.
    And then to find the values of the x and y launch a table.
    It would be possible that?
    By invez of entering with a number so that the program sustitua a function ja existing as Ex2, seen above, entering with a function quaquer (type: y = x ^ 2 +1) for the program atribuisse values to that function and then create a table of values as Ex1.
    I hope it has been easier to understand my doubts now.
    Thank you for your attention!
    God bless!

    rafaelmenezes wrote:
    Thanks for the explanation, could understand what fly said.
    But as it applied to a program?
    How to create a program that recognizes that the entry coefficients?Are you asking about how to parse out the coefficients from the string "3x^4 + 4x^3 - 8x^2 + 5x^1 + 2x^0"? If you define the format to strictly follow that example, this should get you started:
    Strip out the spaces
    Split the String on "x^"
    That should give you [3, 4+4, 3-8, 2+5, 1+2, 0]
    Split each resulting String on "+ | -", preserving the operator as a token so you can apply the correct sign to the coeff.
    That should leave you with [3, 4, +, 4, 3, -, 8, 2, +, 5, 1, +, 2, 0]. Every other number is a coeff, the rest are the degrees.
    You can strip out the +, since those coeffs are already positive, and strip out the - after negating the following number. This is all assuming that you have to write this yourself. There is no doubt already a library or 5 out there that does this for you.

  • How to execute a java program by clicking !?!?

    Just a click to execute a java program?!!
    Like the ".exe" in Windows or "x" permission in Unix ?!?!?!
    How can I do that?
    And how to set a java program file to display as a personal icon? (My Icon)
    :-)

    Well this is what I do in Windows (I use XP but it works in others):
    First you have to make sure all the class files are in the same folder (duh)
    Then you copy your java.exe from your jre folder into the folder with all your class files.
    Finally, you create a shortcut to java.exe and add your class name to the command line on the shortcut.
    Now all you have to do is double click on the shortcut and your program runs. Sure it's not that pretty but it works.

  • How to write the java program to retrieve the last 7 days dates

    Hi,
    I am having requirement that how to write the java program to retrieve the last 7 days dates. Please help me.
    Regards,
    Ahamad

    It needs any jar file.Of course!
    I did using jscape.My program is running fine.But it
    requires jar file.Which is licensed version.Maybe you should follow the link the the 'license' on the site I posted!
    >
    I have the doubt is apache provides jar file free
    versionMaybe you should follow the link the the 'license' on the site I posted!

  • How to Use the JAVA SCRIPT code in .htm page of the component

    Hi .
    In my requirement i have to use Java Script Function in .htm code ..how to use the java script code and functions in .htm???
    thank you
    B.Mani

    Check this document  [Arun's Blog|http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebClientUI-TalkingwithJava+Script]
    Regards
    Kavindra

  • How to use standard report program [RPR_ABAP_SOURCE_SCAN]

    hi all,
    how to use RPR_ABAP_SOURCE_SCAN report program for checking my program. when i run it its asking me the report name and i gav it but, its showing me the error message as  'ENTER SEARCH STRING' .
    SO I NEED TO KNOW WHERE I DID WRONG.
    thanks in advance,
    suresh babu aluri.

    hi suresh,
    i hav tried that, its working
    enter like this,
    <b>program name : zpy_text</b>
    under search criteria.
    <b>Find string : select</b> 
    "******enter any string that is in that program, usually select will be there, then execute.
    With Regards,
    S.Barani

Maybe you are looking for