Peace be unto you.
The following code runs nicely on my machine (Windows Me).
Screenshot
http://members.rogers.com/mromarkhan/jconio/shot.gif
Dll
http://members.rogers.com/mromarkhan/jconio/JConioLib.dll
I compiled it using MingW which includes Conio.c and Conio.h.
-- QuranBrowser.java
<code>
class QuranBrowser
{
public static void main(String[] args)
{
JConioLib conio = new JConioLib();
conio.setConsoleTitle("Quran Browser"); // rename title from Java
conio.textbackground(JConioLib.WHITE); // white background
conio.textcolor(JConioLib.BLACK); // black text
conio.clrscr(); // clear screen
char c;
int recordPointer = 0;
String [] records = {
"I seek Allah's protection from",
"Satan the outcast",
"In the name of Allah, the Beneficent, the Merciful",
"Praise be to Allah, Lord of the Worlds",
"The Beneficent, the Merciful",
"Owner of the Day of Judgement",
"You we worship, You we ask for help",
"Show us the straight path",
"The path of those whom you have favoured",
"Not of those who earn you anger",
"Nor of those who go astray",
"Accept the prayer"
};
conio.clrscr();
conio.gotoxy(1,14);
System.out.println("Press q to quit");
while(true)
{
conio.gotoxy(1,1);
System.out.println("Press any key to continue");
c = (char)conio.getch();
recordPointer++;
if(c == 'q' || c == 'x')
{
conio.textbackground(JConioLib.RED);
conio.textcolor(JConioLib.WHITE);
conio.gotoxy(1,14);
System.out.println("Press any key to quit");
conio.getch();
break;
}
if(recordPointer >= records.length)
{
recordPointer = 0;
}
else if(recordPointer < 0)
{
recordPointer = records.length-1;
}
for(int i = 0;i<records.length;i++)
{
conio.gotoxy(1,i+2);
if(i == recordPointer)
{
conio.textbackground(JConioLib.GREEN);
conio.textcolor(JConioLib.WHITE);
}
else
{
conio.textbackground(JConioLib.WHITE);
conio.textcolor(JConioLib.BLACK);
}
System.out.println(records
);
}
}
}
}
</code>
<code>
-- JConioLib.java
public class JConioLib
{
public static final int BLACK = 0;
public static final int BLUE = 1;
public static final int GREEN = 2;
public static final int CYAN = 3;
public static final int RED = 4;
public static final int MAGENTA = 5;
public static final int BROWN = 6;
public static final int LIGHTGRAY = 7;
public static final int DARKGRAY = 8;
public static final int LIGHTBLUE = 9;
public static final int LIGHTGREEN = 10;
public static final int LIGHTCYAN = 11;
public static final int LIGHTRED = 12;
public static final int LIGHTMAGENTA = 13;
public static final int YELLOW = 14;
public static final int WHITE = 15;
//void _setcursortype (int type); 1 -100
//textattr (int _attr)
public native String conio_gettext(int left, int top, int right, int bottom);
public native int wherex();
public native int wherey();
public native void delline ();
public native void clreol ();
public native void puttext (int left, int top, int right, int bottom, String s);
public native int getche ();
public native int kbhit ();
public native int putch (int ch);
public native int ungetch (int ch);
public native int getch();
public native void clrscr();
public native void textcolor(int color);
public native void textbackground (int color);
public native void gotoxy(int x, int y);
public native void setConsoleTitle(String title);
static
{
System.loadLibrary("JConioLib");
}
}
</code>
-- JConioLib.c
<code>
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include "JConioLib.h"
#include "conio.h"
#include <windows.h>
//extern void clrscr(void);
/*
* Class: JConioLib
* Method: getch
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_JConioLib_getch
(JNIEnv * env, jobject obj)
{
int c = getch();
return (jint) c;
}
/*
* Class: JConioLib
* Method: clrscr
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_JConioLib_clrscr
(JNIEnv * env, jobject obj)
{
clrscr();
}
/*
* Class: JConioLib
* Method: textcolor
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_JConioLib_textcolor
(JNIEnv * env, jobject obj,jint color)
{
textcolor(color);
}
/*
* Class: JConioLib
* Method: textbackground
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_JConioLib_textbackground
(JNIEnv * env, jobject obj,jint color)
{
textbackground(color);
}
/*
* Class: JConioLib
* Method: puttext
* Signature: (IIIILjava/lang/StringV
*
*/
JNIEXPORT void JNICALL Java_JConioLib_puttext
(JNIEnv * env, jobject obj, jint left, jint top, jint right, jint bottom, jstring prompt)
{
char buf[128];
const char *str = (*env)->GetStringUTFChars(env, prompt, 0);
puttext(left,top,right,bottom,str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
}
/*
* Class: JConioLib
* Method: wherex
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_JConioLib_wherex
(JNIEnv * env, jobject obj)
{
return (jint) wherex();
}
/*
* Class: JConioLib
* Method: wherey
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_JConioLib_wherey
(JNIEnv * env, jobject obj)
{
return (jint) wherey();
}
/*
* Class: JConioLib
* Method: delline
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_JConioLib_delline
(JNIEnv * env, jobject obj)
{
delline();
}
/*
* Class: JConioLib
* Method: clreol
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_JConioLib_clreol
(JNIEnv * env, jobject obj)
{
clreol();
}
/*
* Class: JConioLib
* Method: getche
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_JConioLib_getche
(JNIEnv * env, jobject obj)
{
(jint) getche();
}
/*
* Class: JConioLib
* Method: kbhit
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_JConioLib_kbhit
(JNIEnv * env, jobject obj)
{
return (jint)kbhit();
}
/*
* Class: JConioLib
* Method: putch
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_JConioLib_putch
(JNIEnv * env, jobject obj, jint ch)
{
return (jint) putch(ch);
}
/*
* Class: JConioLib
* Method: ungetch
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_JConioLib_ungetch
(JNIEnv * env, jobject obj, jint ch)
{
return (jint) ungetch(ch);
}
/*
* Class: JConioLib
* Method: gotoxy
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_JConioLib_gotoxy
(JNIEnv * env, jobject obj, jint x, jint y)
{
gotoxy(x,y);
}
/*
* Class: JConioLib
* Method: conio_gettext
* Signature: (IIII)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_JConioLib_conio_1gettext
(JNIEnv * env, jobject obj, jint left, jint top, jint right, jint bottom)
{
char buf[1928];
_conio_gettext(left,top,right,bottom,buf);
return (*env)->NewStringUTF(env, buf);
}
/*
* Class: JConioLib
* Method: setConsoleTitle
* Signature: (Ljava/lang/StringV
*/
JNIEXPORT void JNICALL Java_JConioLib_setConsoleTitle
(JNIEnv * env, jobject obj, jstring title)
{
char buf[128];
const char *str = (*env)->GetStringUTFChars(env, title, 0);
SetConsoleTitle(str);
(*env)->ReleaseStringUTFChars(env, title, str);
}
</code>
-- To Build
// Compile to object not executable
gcc -c conio.c
javac JConioLib.java
// Generate header
javah -jni JConioLib
// compile to Object not executable notice forward slash
gcc -g -O2 -c -IC:/MinGW/include -Ic:/j2sdk1.4.2_04/include -Ic:/j2sdk1.4.2_04/include/win32 -g JConioLib.c
// create dll
dllwrap --output-def JConioLib.def --add-stdcall-alias -o JConioLib.dll JConioLib.o conio.o
//Compile and run test
javac JConioTest.java
java JConioTest
Have a good day