Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
|
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2007, 12:11 AM
Authorized User
 
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default how can clear the screen the screen

what function we used to clear the screen in console

K.Mallikarjunarao
__________________
K.Mallikarjunarao
 
Old January 14th, 2009, 07:08 PM
Registered User
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default clear screen

1- this is OS specific! so not portable. In DOS, use "cls"; in UNIX "tput clear".
2- so use the Runtime class to pass the appropriate OS command to the OS. In the little sample it clear a UNIX screen clear.

/*
** Cmd - used to run a unix command and get the result back
*/
Code:
import java.io.*;
public class Cmd {
public static void main(String[] args) {
try {
String cmd = "/usr/bin/tput clear";
String line;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.print(line);
}
input.close();
} catch (Exception err) {
err.printStackTrace();
System.exit( 100 );
}
return;
}
}
 
Old January 14th, 2009, 07:57 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Not to ask two silly questions, but...
(1) Why did you answer a question that was asked almost 2 years ago?
(2) If we are talking about CONSOLE windows, why not just send about 100 or so blank lines?
 
Old January 16th, 2009, 01:56 PM
Registered User
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1- because I had just used this for the first time, and never looked at the date
2- becasue I didn't see any other replies
3- the same reason Edmund Hillary climbed Evenest - "becasue it was there"
4- if old questions shouldn't be answered maybe Wrox should purge then (if unanswered)

For your last question -
- well theres always many solutions to a problem, but depending on the goal of the designer but I don't like your (albeit much easier solution) becasue for one you could cursor back and see the data!
 
Old January 17th, 2009, 12:43 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

LOL! All fine answers. Have to admit that I wouldn't think that scrolling back to see old screen would be bad, since in today's world I would hope you would only be using console output for hacky utility programs. But never mind, your objection is a fine one. Especially for those who haven't heard of windows (with a lower case w). <grin/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Full screen watashi C# 2005 4 August 7th, 2007 01:05 AM
filling the screen darkhalf CSS Cascading Style Sheets 0 September 26th, 2006 02:29 PM
Draw on the screen without clearing the screen pu132 Visual Basic 2005 Basics 0 August 25th, 2006 09:03 PM
Touch screen Stanny Access 2 August 23rd, 2005 11:12 AM
Splash Screen dodorisio Beginning VB 6 3 March 25th, 2004 08:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.