473,883 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clear the Screen

Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave
Jul 17 '05
19 105856
"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message news:<Kv******* ********@news-server.bigpond. net.au>...
Ive seen this question before- with no real solution.
Surely it wouldnt have been difficult to provide a clear screen, and even
basic screen cursor positioning?
It would make text-mode java alot more useful.


Changing the cursor positions, clearing the screen, setting console
colurs...these are all functions of the console in use, not of Java.
One of the clear screen solutions touched on this by feeding the
correct escape sequence to the console to manipulate it with the
desired effect.

As you can imagine, this is tedious and time consuming. JCurses has
already been mentioned. It is an implementation of nCurses which
determines the console type being used, and wraps escape sequences
with a nice API, independant of the type of console being used.

It should be here:
http://sourceforge.net/projects/javacurses/

However, I can't help but wonder that if you need this type of
functionality from the console, perhaps you should consider the more
standard Java/Swing and make a nice GUI interface to your application.

---
Jared Dykstra
http://www.bork.org/~jared
Jul 17 '05 #11
mmm... interesting
Just tried- it works on the Linux box, but unfortunately it doesnt on
Windows- just prints a gender symbol. darn.
Going to look at jcurses

"Christian" <ja******@email user.net> wrote in message
news:32******** *************** ***@posting.goo gle.com...
Printing out the form-feed character will clear the screen

System.out.prin t("\f");

Hope this helps!

Christian

Jul 17 '05 #12
http://www.xdweb.net/~dibblego/javafaq/javafaq.html#q30

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
"Dave" <bigdavepotnood le*SPAM*hotmail .com> wrote in message
news:3f******** *************** @news-text.dial.pipex .com...
Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave

Jul 17 '05 #13

"Stewart Gordon" <sm*******@yaho o.com> wrote in message
news:bt******** **@sun-cc204.lut.ac.uk ...
While it was 9/1/04 3:04 pm throughout the UK, nos sprinkled little
black dots on a white screen, and they fell thus:
But if they can implement "beep", and they do,
they should be able to implement "cls" too. <snip top of upside-down reply>

That's because BEL is a standard ASCII character
(code 7) and it's pretty much standard that any terminal/console
would render it by beeping.


Try it on an IBM mainframe - they use EBCDIC, not ASCII ;) !

OTOH, for some reason I can't imagine FF (12) doesn't
standardly mean clear screen, and nor does any other
ASCII string.

You'll find that 'plain vanilla' *NIX / Linux systems *do* exhibit fairly
consistent console behaviour; it's the Windows-family environments that
exhibit such inconsistencies .

But I agree that having a portable means of screen clearing
would be handy.

Maybe a nested class could be added to 'System', containing all the
system-specific console-management routines, something like:

class System
{
...
public class Console
{
...
public static native void cls();
public static native void setCurPos(int row, int col);
public static native String inputString();
public static native double inputNumeric();
...
}
...
}

You could then do something like:

System.Console. cls();

to clear the screen, and something like:

String name;

System.Console. setCurPos(10, 35);
System.out.prin t("Enter your name: ");
name = System.Console. inputString();

Platforms that did not support consoles or the like could then simply have
dummy [i.e. empty] methods ?

Maybe if the Sun Java developers were lobbied by enough developers they
might consider building this functionality into the API ?

I suspect, though, they will simply leave it to developers requiring console
management support to use JNI, either directly, or by downloading a package
like JCurses.

BTW, have the rest of you people stopped telling people
to try what you can't be bothered to try for yourself?


I think their intentions were sincere, and probably did do some testing on
their own systems. The error was in assuming that the same behaviour could
be expected on other systems. My general view is that any constructive
response is to be welcomed and appreciated.

Cheers,

Anthony Borla
Jul 17 '05 #14
nos

"Stewart Gordon" <sm*******@yaho o.com> wrote in message
news:bt******** **@sun-cc204.lut.ac.uk ...
While it was 9/1/04 3:04 pm throughout the UK, nos sprinkled little
black dots on a white screen, and they fell thus:
But if they can implement "beep", and they do,
they should be able to implement "cls" too. <snip top of upside-down reply>

That's because BEL is a standard ASCII character (code 7) and it's
pretty much standard that any terminal/console would render it by
beeping. OTOH, for some reason I can't imagine FF (12) doesn't
standardly mean clear screen, and nor does any other ASCII string.

I thought I would try to find out how beep works by looking in the java
sdk files but i could not figure it out. All i found was

public abstract void beep();
in java/awt/Toolkit.java
But I agree that having a portable means of screen clearing would be
handy. BTW, have the rest of you people stopped telling people to try
what you can't be bothered to try for yourself?

Stewart.

--
My e-mail is valid but not my primary mailbox, aside from its being the
unfortunate victim of intensive mail-bombing at the moment. Please keep
replies on the 'group where everyone may benefit.

Jul 17 '05 #15
Something like this Console class would be great.
Ive just downloaded JCurses but so far looks like overkill- when just a few
methods like clear screen and cursor position would go such a long way...

"Anthony Borla" <aj*****@bigpon d.com> wrote in message
news:yA******** *******@news-server.bigpond. net.au...

"Stewart Gordon" <sm*******@yaho o.com> wrote in message
news:bt******** **@sun-cc204.lut.ac.uk ...
While it was 9/1/04 3:04 pm throughout the UK, nos sprinkled little
black dots on a white screen, and they fell thus:
But if they can implement "beep", and they do,
they should be able to implement "cls" too. <snip top of upside-down reply>

That's because BEL is a standard ASCII character
(code 7) and it's pretty much standard that any terminal/console
would render it by beeping.


Try it on an IBM mainframe - they use EBCDIC, not ASCII ;) !

OTOH, for some reason I can't imagine FF (12) doesn't
standardly mean clear screen, and nor does any other
ASCII string.


You'll find that 'plain vanilla' *NIX / Linux systems *do* exhibit fairly
consistent console behaviour; it's the Windows-family environments that
exhibit such inconsistencies .

But I agree that having a portable means of screen clearing
would be handy.


Maybe a nested class could be added to 'System', containing all the
system-specific console-management routines, something like:

class System
{
...
public class Console
{
...
public static native void cls();
public static native void setCurPos(int row, int col);
public static native String inputString();
public static native double inputNumeric();
...
}
...
}

You could then do something like:

System.Console. cls();

to clear the screen, and something like:

String name;

System.Console. setCurPos(10, 35);
System.out.prin t("Enter your name: ");
name = System.Console. inputString();

Platforms that did not support consoles or the like could then simply have
dummy [i.e. empty] methods ?

Maybe if the Sun Java developers were lobbied by enough developers they
might consider building this functionality into the API ?

I suspect, though, they will simply leave it to developers requiring

console management support to use JNI, either directly, or by downloading a package like JCurses.

BTW, have the rest of you people stopped telling people
to try what you can't be bothered to try for yourself?


I think their intentions were sincere, and probably did do some testing on
their own systems. The error was in assuming that the same behaviour could
be expected on other systems. My general view is that any constructive
response is to be welcomed and appreciated.

Cheers,

Anthony Borla

Jul 17 '05 #16
It would defeat the purpose of platform-independance, since not all
platforms have the concept of a "console".

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software

"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Hz******** ********@news-server.bigpond. net.au...
Something like this Console class would be great.
Ive just downloaded JCurses but so far looks like overkill- when just a few methods like clear screen and cursor position would go such a long way...

"Anthony Borla" <aj*****@bigpon d.com> wrote in message
news:yA******** *******@news-server.bigpond. net.au...

"Stewart Gordon" <sm*******@yaho o.com> wrote in message
news:bt******** **@sun-cc204.lut.ac.uk ...
While it was 9/1/04 3:04 pm throughout the UK, nos sprinkled little
black dots on a white screen, and they fell thus:

> But if they can implement "beep", and they do,
> they should be able to implement "cls" too.
<snip top of upside-down reply>

That's because BEL is a standard ASCII character
(code 7) and it's pretty much standard that any terminal/console
would render it by beeping.


Try it on an IBM mainframe - they use EBCDIC, not ASCII ;) !

OTOH, for some reason I can't imagine FF (12) doesn't
standardly mean clear screen, and nor does any other
ASCII string.


You'll find that 'plain vanilla' *NIX / Linux systems *do* exhibit fairly consistent console behaviour; it's the Windows-family environments that
exhibit such inconsistencies .

But I agree that having a portable means of screen clearing
would be handy.


Maybe a nested class could be added to 'System', containing all the
system-specific console-management routines, something like:

class System
{
...
public class Console
{
...
public static native void cls();
public static native void setCurPos(int row, int col);
public static native String inputString();
public static native double inputNumeric();
...
}
...
}

You could then do something like:

System.Console. cls();

to clear the screen, and something like:

String name;

System.Console. setCurPos(10, 35);
System.out.prin t("Enter your name: ");
name = System.Console. inputString();

Platforms that did not support consoles or the like could then simply have dummy [i.e. empty] methods ?

Maybe if the Sun Java developers were lobbied by enough developers they
might consider building this functionality into the API ?

I suspect, though, they will simply leave it to developers requiring

console
management support to use JNI, either directly, or by downloading a

package
like JCurses.

BTW, have the rest of you people stopped telling people
to try what you can't be bothered to try for yourself?


I think their intentions were sincere, and probably did do some testing on their own systems. The error was in assuming that the same behaviour could be expected on other systems. My general view is that any constructive
response is to be welcomed and appreciated.

Cheers,

Anthony Borla


Jul 17 '05 #17

"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Hz******** ********@news-server.bigpond. net.au...

Something like this Console class would be
great. Ive just downloaded JCurses but so far looks
like overkill- when just a few methods like clear screen
and cursor position would go such a long way...


I quite like JCurses, *but* I fully agree with you - too much functionality.
Having thought about it a little more, all that is minimally required:

* Console information accessor [e.g. get max lines, columns, etc]
* A clear screen method
* Cursor position set / get methods
* A character read method i.e. accept a sing;le character
without needing to press ENTER [could be designed to
also accept 'special' keys like F1, though best, I think, to
keep it simple and ignore non-standard keys]

with other functionality such as:

* A string read method [e.g. up to X characters in
length without pressing ENTER; ESC could abort
input process; extend to not echo typed keys so
as to allow password-type input]
* Support character atributes like colour etc
* Cursor hide / unhide

would be purely optional.

It is easy enough to make a start with this by creating a Console class:

public class Console
{
public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

Below you will find a JNI implementation for such a class. Since we're
dealing with JNI such code is strictly system-specific, so will work only on
the targeted platform, in this case, Win32 i.e. it should run ok on all
Win9x and up platforms.

The included files:

* A batch file called 'mkConsole.bat' used to document / generate
the steps in creating the native code

* The Java source files:

- Console.java, the Java interface to the JNI routines
- TestConsole.jav a, a minimal test harness for these routines

* C++ source files:

- Console.h
- ConsoleImp.cpp

Assuming you use a Win32 system [I hope so :)] you will need to provide:

* C++ Compiler capable of generating Win32 DLL's
* Suitable 'make' file for this compiler

The code was tested with Borland 5.5.1 and J2SDK 1.4.1, and appears to work
ok. The code is provided 'as is' for educational purposes. It goes without
saying that I accept no reponsibility for this code's use by others.

It may be worthwhile for anyone contemplating the use of this code to first:

* Read the JNI tutorial on the Sun site
* Consult Win32 documentation regarding 'console applications'
for some insight into the code

Sadly, the codes its provision alienates a substantial segment of the Java
community. It is hoped, though, that other may be motivated to implement
this, or similar functionality, for their own platform, and - hopefully -
post it. It would be interesting to see how these simple tasks are performed
on other platforms.

I hope this helps.

Anthony Borla

// FILE: mkConsole.bat =============== =========
@echo off

:: Compile JAVA Source containing Native Method calls
javac -deprecation TestConsole.jav a

:: Create .h header from Java Source
javah -jni TestConsole

:: Implement Native Method (C++) and create a .DLL
:: 1) Compile ConsoleImp.cpp
:: 2) Create ConsoleImp.dll
:: *** You need to implement this for your compiler ***
make -fConsoleImp.mak

:: Execute Java Program which calls Native Method
:: 1) Loads ConsoleImp.dll
:: 2) Calls 'Console' native method
java TestConsole
// FILE: Console.java =============== =========
public class Console
{
// Load DLL
static
{
try
{
System.loadLibr ary("ConsoleImp ");
}

catch (UnsatisfiedLin kError e)
{
System.out.prin tln("Could not locate DLL");
System.exit(1);
}
}

public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

// FILE: TestConsole.jav a =============== ======
public class TestConsole
{
public static void main(String[] args)
{
System.out.prin tln("Start...") ;

Console.cls();

System.out.prin tln(Console.get MaxRows());
System.out.prin tln(Console.get MaxCols());

Console.setCurP os(10, 5);

System.out.prin tln(Console.get CurRow());
System.out.prin tln(Console.get CurCol());

char key;
int[] keyData = new int[]{0, 0};

System.out.prin t("Press a key: ");
key = Console.inputKe y(keyData);

System.out.prin t(key + ", " + (int)key);

if (key == 0)
System.out.prin tln("A special key was pressed");

System.out.prin tln("Key Code: " + keyData[0]);
System.out.prin tln("Key Scan: " + keyData[1]);

System.out.prin tln("End...");
}
}
// FILE: Console.h =============== =========
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Console */

#ifndef _Included_Conso le
#define _Included_Conso le
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Console
* Method: getMaxRows
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxRows
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getMaxCols
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxCols
(JNIEnv *, jclass);

/*
* Class: Console
* Method: cls
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Console_cl s
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurRow
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurRow
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurCol
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurCol
(JNIEnv *, jclass);

/*
* Class: Console
* Method: setCurPos
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_Console_se tCurPos
(JNIEnv *, jclass, jint, jint);

/*
* Class: Console
* Method: inputKey
* Signature: ([I)C
*/
JNIEXPORT jchar JNICALL Java_Console_in putKey
(JNIEnv *, jclass, jintArray);

#ifdef __cplusplus
}
#endif
#endif

// FILE: ConsoleImp.cpp =============== =======
// *** Plaform-specific Header(s)
// *** Here is for Win32
#include <windows.h>
// ***

#include <jni.h>
#include "Console.h"

JNIEXPORT jint JNICALL Java_Console_ge tMaxRows(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tMaxCols(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.X;
}

JNIEXPORT void JNICALL Java_Console_cl s(JNIEnv *, jclass)
{
COORD coordScreen = { 0, 0 };
CONSOLE_SCREEN_ BUFFER_INFO csbi;

DWORD cCharsWritten;
DWORD dwConSize;

HANDLE hConsole = ::GetStdHandle( STD_OUTPUT_HAND LE);

// Get the number of character cells in the current buffer
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Compute Console size
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

// Fill the entire screen with blanks
::FillConsoleOu tputCharacter(h Console, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten) ;

// Get the current text attribute
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Set the buffer's attributes accordingly
::FillConsoleOu tputAttribute(h Console, csbi.wAttribute s,
dwConSize, coordScreen, &cCharsWritten) ;

// Home the cursor at (0, 0)
::SetConsoleCur sorPosition(hCo nsole, coordScreen);

return;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurRow(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurCol(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.X;
}

JNIEXPORT void JNICALL Java_Console_se tCurPos(JNIEnv* env, jclass obj, jint
row, jint col)
{
COORD coord; coord.X = col; coord.Y = row;

::SetConsoleCur sorPosition(
::GetStdHandle( STD_OUTPUT_HAND LE), coord);
}

JNIEXPORT jchar JNICALL Java_Console_in putKey(JNIEnv* env, jclass obj,
jintArray keyData)
{
const char NUL = '\0',
ESC = '\x1B';

const int TIMEOUT_MILLIS = 1000;

jsize len = env->GetArrayLength (keyData);
jint* keyData_ = env->GetIntArrayEle ments(keyData, 0);

DWORD omode, nmode; DWORD itemsRead = 0;
INPUT_RECORD ir;
char inputBuffer[4] = { NUL };

HANDLE hConsole = ::GetStdHandle( STD_INPUT_HANDL E);

::GetConsoleMod e(hConsole, &omode);
nmode = omode & ~ENABLE_LINE_IN PUT & ~ENABLE_ECHO_IN PUT;
::SetConsoleMod e(hConsole, nmode);

do
{
::FlushConsoleI nputBuffer(hCon sole);
::WaitForSingle Object(hConsole , TIMEOUT_MILLIS) ;
::PeekConsoleIn put(hConsole, &ir, 1, &itemsRead);

if (itemsRead > 0)
{
if (ir.EventType == KEY_EVENT)
{
// Discard all non-keydown events
if (ir.Event.KeyEv ent.bKeyDown == FALSE)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
continue;
}

// Got ASCII key, so extract, flush, and exit
if (ir.Event.KeyEv ent.uChar.Ascii Char != NUL)
{
if (ir.Event.KeyEv ent.uChar.Ascii Char == ESC)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
inputBuffer[0] = ESC;
}
else
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;

break;
}

// Got 'special' key, so determine appropriate actions
switch (ir.Event.KeyEv ent.dwControlKe yState)
{
case ENHANCED_KEY:
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
break;

case LEFT_ALT_PRESSE D: case LEFT_CTRL_PRESS ED:
case RIGHT_ALT_PRESS ED: case RIGHT_CTRL_PRES SED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
inputBuffer[0] = NUL;
break;

case SHIFT_PRESSED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
break;
}

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;
}
else
{
// Not Key Event, so just extract and discard
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
}
}

} while (itemsRead == 0);

::FlushConsoleI nputBuffer(hCon sole);
::SetConsoleMod e(hConsole, omode);

env->ReleaseIntArra yElements(keyDa ta, keyData_, 0);

return inputBuffer[0];
}

Jul 17 '05 #18
Can anyone help me with this one? I am looking for a makefile to fill
in for the one mentioned in the previous posting for so I can compile
this all myself. I have the Borland v5.5 command line tools. I have no
clue where to go here. I tried skipping the 'makefile' idea and tried
using following syntax and it compiled but I don't think it compiled
the way it supposed to (windows freaked when I tried to use the DLL)

cpp32 -I\j2sdk1.4.2_03 \include -I\j2sdk1.4.2_03 \include\win
32 -I\Borland\BCC55 \Include -oConsoleImp.dll ConsoleImp.cpp

So I am assuming I am missing a lot here. Any help would be
appreciated.

Russ

"Anthony Borla" <aj*****@bigpon d.com> wrote in message news:<UO******* *********@news-server.bigpond. net.au>...
"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Hz******** ********@news-server.bigpond. net.au...

Something like this Console class would be
great. Ive just downloaded JCurses but so far looks
like overkill- when just a few methods like clear screen
and cursor position would go such a long way...


I quite like JCurses, *but* I fully agree with you - too much functionality.
Having thought about it a little more, all that is minimally required:

* Console information accessor [e.g. get max lines, columns, etc]
* A clear screen method
* Cursor position set / get methods
* A character read method i.e. accept a sing;le character
without needing to press ENTER [could be designed to
also accept 'special' keys like F1, though best, I think, to
keep it simple and ignore non-standard keys]

with other functionality such as:

* A string read method [e.g. up to X characters in
length without pressing ENTER; ESC could abort
input process; extend to not echo typed keys so
as to allow password-type input]
* Support character atributes like colour etc
* Cursor hide / unhide

would be purely optional.

It is easy enough to make a start with this by creating a Console class:

public class Console
{
public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

Below you will find a JNI implementation for such a class. Since we're
dealing with JNI such code is strictly system-specific, so will work only on
the targeted platform, in this case, Win32 i.e. it should run ok on all
Win9x and up platforms.

The included files:

* A batch file called 'mkConsole.bat' used to document / generate
the steps in creating the native code

* The Java source files:

- Console.java, the Java interface to the JNI routines
- TestConsole.jav a, a minimal test harness for these routines

* C++ source files:

- Console.h
- ConsoleImp.cpp

Assuming you use a Win32 system [I hope so :)] you will need to provide:

* C++ Compiler capable of generating Win32 DLL's
* Suitable 'make' file for this compiler

The code was tested with Borland 5.5.1 and J2SDK 1.4.1, and appears to work
ok. The code is provided 'as is' for educational purposes. It goes without
saying that I accept no reponsibility for this code's use by others.

It may be worthwhile for anyone contemplating the use of this code to first:

* Read the JNI tutorial on the Sun site
* Consult Win32 documentation regarding 'console applications'
for some insight into the code

Sadly, the codes its provision alienates a substantial segment of the Java
community. It is hoped, though, that other may be motivated to implement
this, or similar functionality, for their own platform, and - hopefully -
post it. It would be interesting to see how these simple tasks are performed
on other platforms.

I hope this helps.

Anthony Borla

// FILE: mkConsole.bat =============== =========
@echo off

:: Compile JAVA Source containing Native Method calls
javac -deprecation TestConsole.jav a

:: Create .h header from Java Source
javah -jni TestConsole

:: Implement Native Method (C++) and create a .DLL
:: 1) Compile ConsoleImp.cpp
:: 2) Create ConsoleImp.dll
:: *** You need to implement this for your compiler ***
make -fConsoleImp.mak

:: Execute Java Program which calls Native Method
:: 1) Loads ConsoleImp.dll
:: 2) Calls 'Console' native method
java TestConsole
// FILE: Console.java =============== =========
public class Console
{
// Load DLL
static
{
try
{
System.loadLibr ary("ConsoleImp ");
}

catch (UnsatisfiedLin kError e)
{
System.out.prin tln("Could not locate DLL");
System.exit(1);
}
}

public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

// FILE: TestConsole.jav a =============== ======
public class TestConsole
{
public static void main(String[] args)
{
System.out.prin tln("Start...") ;

Console.cls();

System.out.prin tln(Console.get MaxRows());
System.out.prin tln(Console.get MaxCols());

Console.setCurP os(10, 5);

System.out.prin tln(Console.get CurRow());
System.out.prin tln(Console.get CurCol());

char key;
int[] keyData = new int[]{0, 0};

System.out.prin t("Press a key: ");
key = Console.inputKe y(keyData);

System.out.prin t(key + ", " + (int)key);

if (key == 0)
System.out.prin tln("A special key was pressed");

System.out.prin tln("Key Code: " + keyData[0]);
System.out.prin tln("Key Scan: " + keyData[1]);

System.out.prin tln("End...");
}
}
// FILE: Console.h =============== =========
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Console */

#ifndef _Included_Conso le
#define _Included_Conso le
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Console
* Method: getMaxRows
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxRows
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getMaxCols
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxCols
(JNIEnv *, jclass);

/*
* Class: Console
* Method: cls
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Console_cl s
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurRow
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurRow
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurCol
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurCol
(JNIEnv *, jclass);

/*
* Class: Console
* Method: setCurPos
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_Console_se tCurPos
(JNIEnv *, jclass, jint, jint);

/*
* Class: Console
* Method: inputKey
* Signature: ([I)C
*/
JNIEXPORT jchar JNICALL Java_Console_in putKey
(JNIEnv *, jclass, jintArray);

#ifdef __cplusplus
}
#endif
#endif

// FILE: ConsoleImp.cpp =============== =======
// *** Plaform-specific Header(s)
// *** Here is for Win32
#include <windows.h>
// ***

#include <jni.h>
#include "Console.h"

JNIEXPORT jint JNICALL Java_Console_ge tMaxRows(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tMaxCols(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.X;
}

JNIEXPORT void JNICALL Java_Console_cl s(JNIEnv *, jclass)
{
COORD coordScreen = { 0, 0 };
CONSOLE_SCREEN_ BUFFER_INFO csbi;

DWORD cCharsWritten;
DWORD dwConSize;

HANDLE hConsole = ::GetStdHandle( STD_OUTPUT_HAND LE);

// Get the number of character cells in the current buffer
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Compute Console size
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

// Fill the entire screen with blanks
::FillConsoleOu tputCharacter(h Console, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten) ;

// Get the current text attribute
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Set the buffer's attributes accordingly
::FillConsoleOu tputAttribute(h Console, csbi.wAttribute s,
dwConSize, coordScreen, &cCharsWritten) ;

// Home the cursor at (0, 0)
::SetConsoleCur sorPosition(hCo nsole, coordScreen);

return;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurRow(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurCol(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.X;
}

JNIEXPORT void JNICALL Java_Console_se tCurPos(JNIEnv* env, jclass obj, jint
row, jint col)
{
COORD coord; coord.X = col; coord.Y = row;

::SetConsoleCur sorPosition(
::GetStdHandle( STD_OUTPUT_HAND LE), coord);
}

JNIEXPORT jchar JNICALL Java_Console_in putKey(JNIEnv* env, jclass obj,
jintArray keyData)
{
const char NUL = '\0',
ESC = '\x1B';

const int TIMEOUT_MILLIS = 1000;

jsize len = env->GetArrayLength (keyData);
jint* keyData_ = env->GetIntArrayEle ments(keyData, 0);

DWORD omode, nmode; DWORD itemsRead = 0;
INPUT_RECORD ir;
char inputBuffer[4] = { NUL };

HANDLE hConsole = ::GetStdHandle( STD_INPUT_HANDL E);

::GetConsoleMod e(hConsole, &omode);
nmode = omode & ~ENABLE_LINE_IN PUT & ~ENABLE_ECHO_IN PUT;
::SetConsoleMod e(hConsole, nmode);

do
{
::FlushConsoleI nputBuffer(hCon sole);
::WaitForSingle Object(hConsole , TIMEOUT_MILLIS) ;
::PeekConsoleIn put(hConsole, &ir, 1, &itemsRead);

if (itemsRead > 0)
{
if (ir.EventType == KEY_EVENT)
{
// Discard all non-keydown events
if (ir.Event.KeyEv ent.bKeyDown == FALSE)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
continue;
}

// Got ASCII key, so extract, flush, and exit
if (ir.Event.KeyEv ent.uChar.Ascii Char != NUL)
{
if (ir.Event.KeyEv ent.uChar.Ascii Char == ESC)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
inputBuffer[0] = ESC;
}
else
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;

break;
}

// Got 'special' key, so determine appropriate actions
switch (ir.Event.KeyEv ent.dwControlKe yState)
{
case ENHANCED_KEY:
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
break;

case LEFT_ALT_PRESSE D: case LEFT_CTRL_PRESS ED:
case RIGHT_ALT_PRESS ED: case RIGHT_CTRL_PRES SED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
inputBuffer[0] = NUL;
break;

case SHIFT_PRESSED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
break;
}

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;
}
else
{
// Not Key Event, so just extract and discard
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
}
}

} while (itemsRead == 0);

::FlushConsoleI nputBuffer(hCon sole);
::SetConsoleMod e(hConsole, omode);

env->ReleaseIntArra yElements(keyDa ta, keyData_, 0);

return inputBuffer[0];
}

Jul 17 '05 #19
I know from some experience with Linux, the native code you are making into
your library must be position independent.
So when you are making your shared library you need to compile it with the
correct switches.

On Linux you would do something of this fashion
http://www.javaworld.com/javaworld/j...javatip23.html
Look in the "Create a shared library" section of this article.

For Linux this is how it works
http://www.tldp.org/HOWTO/Program-Li...libraries.html

If the library is compiled without being position independent then when you
run it, strange things may happen or it may crap out completely.

Roman.

"Russell Allen" <wh*********@ho tmail.com> wrote in message
news:2c******** *************** *@posting.googl e.com...
Can anyone help me with this one? I am looking for a makefile to fill
in for the one mentioned in the previous posting for so I can compile
this all myself. I have the Borland v5.5 command line tools. I have no
clue where to go here. I tried skipping the 'makefile' idea and tried
using following syntax and it compiled but I don't think it compiled
the way it supposed to (windows freaked when I tried to use the DLL)

cpp32 -I\j2sdk1.4.2_03 \include -I\j2sdk1.4.2_03 \include\win
32 -I\Borland\BCC55 \Include -oConsoleImp.dll ConsoleImp.cpp

So I am assuming I am missing a lot here. Any help would be
appreciated.

Russ

"Anthony Borla" <aj*****@bigpon d.com> wrote in message

news:<UO******* *********@news-server.bigpond. net.au>...
"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Hz******** ********@news-server.bigpond. net.au...

Something like this Console class would be
great. Ive just downloaded JCurses but so far looks
like overkill- when just a few methods like clear screen
and cursor position would go such a long way...


I quite like JCurses, *but* I fully agree with you - too much functionality. Having thought about it a little more, all that is minimally required:

* Console information accessor [e.g. get max lines, columns, etc]
* A clear screen method
* Cursor position set / get methods
* A character read method i.e. accept a sing;le character
without needing to press ENTER [could be designed to
also accept 'special' keys like F1, though best, I think, to
keep it simple and ignore non-standard keys]

with other functionality such as:

* A string read method [e.g. up to X characters in
length without pressing ENTER; ESC could abort
input process; extend to not echo typed keys so
as to allow password-type input]
* Support character atributes like colour etc
* Cursor hide / unhide

would be purely optional.

It is easy enough to make a start with this by creating a Console class:

public class Console
{
public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

Below you will find a JNI implementation for such a class. Since we're
dealing with JNI such code is strictly system-specific, so will work only on the targeted platform, in this case, Win32 i.e. it should run ok on all
Win9x and up platforms.

The included files:

* A batch file called 'mkConsole.bat' used to document / generate
the steps in creating the native code

* The Java source files:

- Console.java, the Java interface to the JNI routines
- TestConsole.jav a, a minimal test harness for these routines

* C++ source files:

- Console.h
- ConsoleImp.cpp

Assuming you use a Win32 system [I hope so :)] you will need to provide:

* C++ Compiler capable of generating Win32 DLL's
* Suitable 'make' file for this compiler

The code was tested with Borland 5.5.1 and J2SDK 1.4.1, and appears to work ok. The code is provided 'as is' for educational purposes. It goes without saying that I accept no reponsibility for this code's use by others.

It may be worthwhile for anyone contemplating the use of this code to first:
* Read the JNI tutorial on the Sun site
* Consult Win32 documentation regarding 'console applications'
for some insight into the code

Sadly, the codes its provision alienates a substantial segment of the Java community. It is hoped, though, that other may be motivated to implement
this, or similar functionality, for their own platform, and - hopefully - post it. It would be interesting to see how these simple tasks are performed on other platforms.

I hope this helps.

Anthony Borla

// FILE: mkConsole.bat =============== =========
@echo off

:: Compile JAVA Source containing Native Method calls
javac -deprecation TestConsole.jav a

:: Create .h header from Java Source
javah -jni TestConsole

:: Implement Native Method (C++) and create a .DLL
:: 1) Compile ConsoleImp.cpp
:: 2) Create ConsoleImp.dll
:: *** You need to implement this for your compiler ***
make -fConsoleImp.mak

:: Execute Java Program which calls Native Method
:: 1) Loads ConsoleImp.dll
:: 2) Calls 'Console' native method
java TestConsole
// FILE: Console.java =============== =========
public class Console
{
// Load DLL
static
{
try
{
System.loadLibr ary("ConsoleImp ");
}

catch (UnsatisfiedLin kError e)
{
System.out.prin tln("Could not locate DLL");
System.exit(1);
}
}

public static native int getMaxRows();
public static native int getMaxCols();

public static native void cls();

public static native int getCurRow();
public static native int getCurCol();

public static native void setCurPos(int row, int col);

public static native char inputKey(int[] keyData);
}

// FILE: TestConsole.jav a =============== ======
public class TestConsole
{
public static void main(String[] args)
{
System.out.prin tln("Start...") ;

Console.cls();

System.out.prin tln(Console.get MaxRows());
System.out.prin tln(Console.get MaxCols());

Console.setCurP os(10, 5);

System.out.prin tln(Console.get CurRow());
System.out.prin tln(Console.get CurCol());

char key;
int[] keyData = new int[]{0, 0};

System.out.prin t("Press a key: ");
key = Console.inputKe y(keyData);

System.out.prin t(key + ", " + (int)key);

if (key == 0)
System.out.prin tln("A special key was pressed");

System.out.prin tln("Key Code: " + keyData[0]);
System.out.prin tln("Key Scan: " + keyData[1]);

System.out.prin tln("End...");
}
}
// FILE: Console.h =============== =========
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Console */

#ifndef _Included_Conso le
#define _Included_Conso le
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Console
* Method: getMaxRows
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxRows
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getMaxCols
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tMaxCols
(JNIEnv *, jclass);

/*
* Class: Console
* Method: cls
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Console_cl s
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurRow
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurRow
(JNIEnv *, jclass);

/*
* Class: Console
* Method: getCurCol
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Console_ge tCurCol
(JNIEnv *, jclass);

/*
* Class: Console
* Method: setCurPos
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_Console_se tCurPos
(JNIEnv *, jclass, jint, jint);

/*
* Class: Console
* Method: inputKey
* Signature: ([I)C
*/
JNIEXPORT jchar JNICALL Java_Console_in putKey
(JNIEnv *, jclass, jintArray);

#ifdef __cplusplus
}
#endif
#endif

// FILE: ConsoleImp.cpp =============== =======
// *** Plaform-specific Header(s)
// *** Here is for Win32
#include <windows.h>
// ***

#include <jni.h>
#include "Console.h"

JNIEXPORT jint JNICALL Java_Console_ge tMaxRows(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tMaxCols(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwSize.X;
}

JNIEXPORT void JNICALL Java_Console_cl s(JNIEnv *, jclass)
{
COORD coordScreen = { 0, 0 };
CONSOLE_SCREEN_ BUFFER_INFO csbi;

DWORD cCharsWritten;
DWORD dwConSize;

HANDLE hConsole = ::GetStdHandle( STD_OUTPUT_HAND LE);

// Get the number of character cells in the current buffer
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Compute Console size
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

// Fill the entire screen with blanks
::FillConsoleOu tputCharacter(h Console, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten) ;

// Get the current text attribute
::GetConsoleScr eenBufferInfo(h Console, &csbi);

// Set the buffer's attributes accordingly
::FillConsoleOu tputAttribute(h Console, csbi.wAttribute s,
dwConSize, coordScreen, &cCharsWritten) ;

// Home the cursor at (0, 0)
::SetConsoleCur sorPosition(hCo nsole, coordScreen);

return;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurRow(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.Y;
}

JNIEXPORT jint JNICALL Java_Console_ge tCurCol(JNIEnv *, jclass)
{
CONSOLE_SCREEN_ BUFFER_INFO csbi;

::GetConsoleScr eenBufferInfo(
::GetStdHandle( STD_OUTPUT_HAND LE), &csbi);

return csbi.dwCursorPo sition.X;
}

JNIEXPORT void JNICALL Java_Console_se tCurPos(JNIEnv* env, jclass obj, jint row, jint col)
{
COORD coord; coord.X = col; coord.Y = row;

::SetConsoleCur sorPosition(
::GetStdHandle( STD_OUTPUT_HAND LE), coord);
}

JNIEXPORT jchar JNICALL Java_Console_in putKey(JNIEnv* env, jclass obj,
jintArray keyData)
{
const char NUL = '\0',
ESC = '\x1B';

const int TIMEOUT_MILLIS = 1000;

jsize len = env->GetArrayLength (keyData);
jint* keyData_ = env->GetIntArrayEle ments(keyData, 0);

DWORD omode, nmode; DWORD itemsRead = 0;
INPUT_RECORD ir;
char inputBuffer[4] = { NUL };

HANDLE hConsole = ::GetStdHandle( STD_INPUT_HANDL E);

::GetConsoleMod e(hConsole, &omode);
nmode = omode & ~ENABLE_LINE_IN PUT & ~ENABLE_ECHO_IN PUT;
::SetConsoleMod e(hConsole, nmode);

do
{
::FlushConsoleI nputBuffer(hCon sole);
::WaitForSingle Object(hConsole , TIMEOUT_MILLIS) ;
::PeekConsoleIn put(hConsole, &ir, 1, &itemsRead);

if (itemsRead > 0)
{
if (ir.EventType == KEY_EVENT)
{
// Discard all non-keydown events
if (ir.Event.KeyEv ent.bKeyDown == FALSE)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
continue;
}

// Got ASCII key, so extract, flush, and exit
if (ir.Event.KeyEv ent.uChar.Ascii Char != NUL)
{
if (ir.Event.KeyEv ent.uChar.Ascii Char == ESC)
{
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
inputBuffer[0] = ESC;
}
else
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;

break;
}

// Got 'special' key, so determine appropriate actions
switch (ir.Event.KeyEv ent.dwControlKe yState)
{
case ENHANCED_KEY:
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
break;

case LEFT_ALT_PRESSE D: case LEFT_CTRL_PRESS ED:
case RIGHT_ALT_PRESS ED: case RIGHT_CTRL_PRES SED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
inputBuffer[0] = NUL;
break;

case SHIFT_PRESSED:
::ReadFile(hCon sole, inputBuffer, 1, &itemsRead, NULL);
break;
}

keyData_[0] = ir.Event.KeyEve nt.wVirtualKeyC ode;
keyData_[1] = ir.Event.KeyEve nt.wVirtualScan Code;
}
else
{
// Not Key Event, so just extract and discard
::ReadConsoleIn put(hConsole, &ir, 1, &itemsRead);
}
}

} while (itemsRead == 0);

::FlushConsoleI nputBuffer(hCon sole);
::SetConsoleMod e(hConsole, omode);

env->ReleaseIntArra yElements(keyDa ta, keyData_, 0);

return inputBuffer[0];
}

Jul 17 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
73338
by: NeoPhreak | last post by:
How would you clearn the screen in a console program??? Thanks NeoPhreak >.<
0
2784
by: Peter | last post by:
I am just trying to learn python, to use for some fairly basic command line utilities which will run in either Windows/DOS or Linux. I cannot find a platform neutral way of manipulating the screen. I don't want to do anything complex, but just:- 1. Clear the screen 2. Print a string at an arbitrary x,y position 3. Receive a single key stroke It seems that under Linux the curses module will do all this and more
20
8163
by: ritchie | last post by:
Hi, I am trying to clear the screen in my program. I am loking for something that will work on all compilers, especially Borland & MS Visual Studio 6. On Visual studio I used 'system("cls");' and this works fine but this won't work for Borland. On Borland I used 'clrscr() ' function and it worked ok, but not for Visual Studio.
4
25778
by: John | last post by:
Hi I have the following in a Perl script. I just want to "clear screen" but it does not work. I don't think I've got my client and server sides confused. Any ideas? <SCRIPT Language="JavaScript"> moveTo (0,0);
8
65199
by: REDBAIT | last post by:
Hi Guys, Am using Windows 2000 and Dev C++ to create C programs. I'm trying to use clear screen and other graphic functions such as positioning output on screen. Have seen some documents that suggest i use curses.h or system("clear") for clear screen, for example but all this has failed.
0
1625
by: sajithamol | last post by:
I have an Applet that has three buttons on it, one being a clear screen button. I have it setup right now so it draws a rectangle the size of the applet and fills it with the background color. But when it does that my other two buttons disappear until I mouse over them again. Is there a better way to clear screen or anyway for the buttons to show back up after the "clear screen"?
2
3809
by: owl | last post by:
and here I thought I was going to finally be able to change the world AND contribute back to python with my amazing clear screen extension - but I can't get it to work. ;( Copying from ZoomHeight.py and someone else's clever print suggestion: ------------------------------------------------- # My Clear extension: clear a window class Clear:
9
19201
by: pbd22 | last post by:
Hi. Does anybody know how to issue a clear screen command like DOS "cls" in a telnet session? Thanks!
5
3480
by: Kid Programmer | last post by:
Hello guys. I was wondering how you can clear the screen in a java program. Here is the code for my program: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; public class GUI {
1
19688
by: sganeshsvk | last post by:
i want to clear the screen command prompt for mysql in windows XP... In linux we use (CTRL + L) for clear the screen in mysql prompt.... i already use this command ( \c ) then ( \! clear ) for clear screen in Mysql windows XP... Plz sir, i want reply must......
0
9936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9791
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10845
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10412
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7970
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7123
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.