Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: java clear screen function

  1. #11
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re:java clear screen function

    good looking out xeno. that really sorta dangerous i already got the jni was thinking about trying to use it this morning. thanks alot man. i don't wanna destroy any machines just wanna write decent java apps. :-\ :-\

  2. #12
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re:java clear screen function

    hey xeno you seem to know your java so i ask you to look at this piece of code from my lil java calculator:

    import java.io.*;
    public class Calculator
    {
       public static void main (String[] args)throws IOException
       {
          BufferedRea der input = new BufferedReader (new InputStreamReader (System.in));
          String tempinput,temp,choose,tempholder;
          int exit = 0,contin = 1;
          float buffer,answer;
          int tempswitch;
          
          
          
          System.out.pri ntln ("Welcome to james's java commandline calculator"
          System.out.pri ntln ("Press any key and then enter to continue"
          input.readLine ();
          
          System.out.pri ntln ("Welcome\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n"
          
          while (exit != 1)
          {
            &n bsp;System.out.println ("select disired process"
            &n bsp;System.out.print ("1.ADD\n2.SUBTRACT\n2.SUBTRACT\n3.DIVIDE\n4. MULTIPLY\n5.SQUAREROOT"
            &n bsp;choose = input.readLine();
            &n bsp;tempswitch = Integer.parseInt(choose);
            &n bsp;switch (tempswitch)
            &n bsp;{
            &n bsp;   case 1:
            &n bsp;       &nbs p; 
            &n bsp;   System.out.println ("Enter Number"
            &n bsp;   tempholder = input.readLine();
            &n bsp;   buffer = Float.parseFloat(tempholder);
            &n bsp;   System.out.println("Ent er next num"
            &n bsp;   tempholder = input.readLine();
            &n bsp;   answer = Float.parseFloat(tempholder);
            &n bsp;   
            &n bsp;   
            &n bsp;   while (contin == 1)
            &n bsp;   {
            &n bsp;      answer = buffer + answer;
            &n bsp;      System.out .println("do you wish to add another set to total y = 1 n = 0"
            &n bsp;      tempholder = input.readLine();
            &n bsp;      contin = Integer.parseInt(tempholder);
            &n bsp;      
            &n bsp;      if (contin != 1)
            &n bsp;      {
            &n bsp;       &nbs p; System.out.println ("answer = :" + answer);
            &n bsp;      }
            &n bsp;      
            &n bsp;      if (contin == 1)
            &n bsp;      {
            &n bsp;       &nbs p; System.out.println("Enter next"
            &n bsp;      }
            &n bsp;      
            &n bsp;      tempholder = input.readLine();
            &n bsp;      buffer = Float.parseFloat(tempholder);
            &n bsp;   }
            &n bsp;   System.out.println("con tinue to use program y = 1 n = 0"
            &n bsp;   tempholder = input.readLine();
            &n bsp;   exit = Integer.parseInt(tempholder);
            &n bsp;   break;
            &n bsp;   
            &n bsp;   
            &n bsp;}
            &n bsp;
            &n bsp;
          }  & nbsp;      
            &n bsp;
       }
    }

    i'm only showing the add portion of the calculator. now the problem i'm having is when i exit from the from the adding code by entering "0" int the exit variable. the program basically comes to a halt it doesn't execute the rest fo the code below:

    System.out.println("continue to use program y = 1 n = 0"
            &n bsp;   tempholder = input.readLine();
            &n bsp;   exit = Integer.parseInt(tempholder);
            &n bsp;   break;

    i don't know why this doesn't work i thought with ever language the concepts of the control structures where the same, ergo, after i change the conditoin "contin" which terminates the loop witht the add code then the code which follows next should be executed "at least so i thought".

    tell me what you think

    ps i know that the code may not be the most efficient thing you've ever seen but i teaching my self so don't laugha at it.

    ;D ;D ;D

  3. #13
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default Re:java clear screen function

    First off, that's a pretty good effort for someone teaching themself Java. I wish some of my classmates @ utech had your kinda drive. Highly commendable.

    Secondly, your program hasn't hung. It has exited the loop. However, unlike C/C++ environments, Java is a very tightly integrated language, and it will not exit the program unless explicitly told to do so.

    Add the following line to the end of your code and see what happens:

    System.exit(0);

  4. #14
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default Re:java clear screen function

    Hey, I hadn't seen this before, but it appears SQLDBA has also answered your question:

    [quote author=SQLDBA link=board=21;threadid=3420;start=0#msg31501 date=1080236862]
    Screen clearing is OS and Hardware dependent depending on the platform call the native API function that is able to clear the screen. lookup Runtime.getRuntime().exec that sould be able to execute a command com command
    [/quote]

    That's another way to clear the screen under Java. It will work! The only problem is that your program will no longer be platform independent.

  5. #15
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re:java clear screen function

    thanx alot xeno and i did see SQLDBA's answer but i had already decided to go wit the \n idea from Cknight i gonna try adding that line to the program and see what happens. but i think you may have mizunderstood me a bit i don't wanna exit the program really, "thanks for the knowledge on how to properly do it", i really want to get the block of code below the loop execute i.e :

    System.out.println("continue to use program y = 1 n = 0"
    tempholder = input.readLine();
    exit = Integer.parseInt(tempholder);

    remeber that there are other functions for the calculator multiply, subtract........ etc. so i have to give the user the option of continue using the program, after he has chosen to calculate the total or exit completely. you see what i trying to say

  6. #16
    Join Date
    Jun 2003
    Posts
    159
    Rep Power
    0

    Default Re:java clear screen function

    If you wnat to keep your app platform independent create a c program. For ex.

    void main()
    {
    clrscr();
    }



    Then call that compiled executable from your java class

  7. #17
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default Re:java clear screen function

    [quote author=death_knight link=board=21;threadid=3420;start=0#msg31615 date=1080482888]
    while (contin == 1)
    {
    answer = buffer + answer;
    System.out.println(& quot;do you wish to add another set to total y = 1 n = 0"
    tempholder = input.readLine();
    contin = Integer.parseInt(tempholder);

    if (contin != 1)
    {
    System.out.pri ntln ("answer = :" + answer);
    }

    /* This code is ignored
    if (contin == 1)
    {
    System.out.pri ntln("Enter next"
    }
    */

    //But your program stops right here:
    tempholder = input.readLine();
    buffer = Float.parseFloat(tempholder);
    }
    System.out.println("c ontinue to use program y = 1 n = 0"
    tempholder = input.readLine();
    exit = Integer.parseInt(tempholder);
    break;
    }
    [/quote]

    Look at the code segment above that I took out. Do you see the area where you have:

    tempholder = input.readLine();
    buffer = Float.parseFloat(tempholder);


    It is still waiting for input, so it never actually gets a chance to exit the loop. Can you see it? What is that piece of code doing there?

  8. #18
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default Re:java clear screen function

    thanx alot xeno and now that i think about it i can't even remember what i put that piece of code there; what was i thinking i don't know ???, i had to sorta put the java on hold because of my final project though, but thanxs alot man. i'll comeback around to completing and compiling that lil program into an exe, just need to at least get my database built.

Posting Permissions

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