Article View: borland.public.jbuilder.java.swing
Article #9074Redirecting System.in
From: Jeroen Zwartepoorte
Date: Tue, 13 Jun 2000 00:00
Date: Tue, 13 Jun 2000 00:00
42 lines
1726 bytes
1726 bytes
Hi,
I'm trying to have System.in point to a JTextArea instead of the command
prompt. To accomplish this, i've written my own InputStream class. The class
works partly: System.in.read() does return character typed in the JTextArea,
but when i use BufferedReader.readLine(), the method never returns
(System.in.read() DOES return '\n' characters). I know JBuilder does exactly
the same thing with success. Any help is appreciated!
Jeroen
class Pl0InputStream extends InputStream {
/** JTextArea. */
private JTextArea fTextArea;
/** Typed keys. */
private Stack fStack = new Stack();
/**
* Constructor.
*/
public Pl0InputStream(JTextArea textArea) {
fTextArea = textArea;
fTextArea.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
synchronized(this) {
fStack.push(new Character(e.getKeyChar()));
}
}
});
}
public int read() {
while (fStack.empty()) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
return ((Character)fStack.pop()).charValue();
}
}
Technical Details
Message-ID:
<8i5dnc$j27@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ed9d203ce9e9692c,start X-Google-Attributes: gid111d45,public From: "Jeroen Zwartepoorte" <Jeroen@xs4all.nl> Subject: Redirecting System.in Date: 2000/06/13 Message-ID: <8i5dnc$j27@bornews.borland.com> X-Deja-AN: 633983852 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing