Simple Tricks to enhance your java cui programs

Today I will tell you how can you enhance your simple java CUI programs and applications with these small tricks and methods

How to clear the output screen through code


If you had ever make a vast java program then you might have been met with the problem on how to clear the output screen when a specific function is called or it is also needed in large menu driven programs .If you want the answer then you are on the Wright track.
In C++ it is easy to clear the screen by just invoking the function clrscr().However java does not provide any predefined function In order to do so yet this one line code can help you to clear the output screen .

System.out.print(“\f”);
I know you could not believe it but its true this one line can clear the output screen.
For your satisfaction see this video practical below.
c




My dprint and dpritln functions


To enhance your cui java program you could use these two user defined functions in your java program these functions can be used in place of of print() and println() of System class.

What’s special in them

These function provide a special typing effect to your cui program dprint() is similar to print() and dprintln() is similar to println().

dprint():-

        
public void dprint(String textToPrint, int timeToWait) 
           {
              int  i;
              for( i=0;i<textToPrint.length();i++)
                    {
                      System.out.print(textToPrint.charAt(i));
                       try
                          {
                            Thread.sleep(timeToWait);// stop the printing process for” timeToWait” mill seconds
                           }
                       catch (Exception e){}

                     }
           }



dprintln():-


                
                 public void dprintln(String textToPrint, int timeToWait)
                 {
                      int  i;
                     for( i=0;i<textToPrint.length();i++)
                         {
                           System.out.print(textToPrint.charAt(i));
                           try
                             {
                              Thread.sleep(timeToWait); // stop the printing process for” timeToWait” mill seconds
                              }
                           catch (Exception e){}
                         }
                           System.out.println();//changes the line
                  }



Here is a video practical which will show you what special effect it gives to the program.




 My halt function


If you have seen the previous video you would have found that there is a time gap between the demonstration between output using normal print and output using dprint() this gap is created  by my halt() it stops the program compilation for  a specific period let’s see how to code it.

public void halt(int timeToWait)  //timeToWait is taken in milliseconds
{
try
{
Thread.sleep(timeToWait); // stop the printing process for” timeToWait” mill seconds
}
catch (Exception e){}

}
Download The Document Here



Hope you like this tutorial .Happy programming

Comments