|
|
|
| Can a Swing GUI JTextArea be used as a console ?
I mean, can be received questions from a java program and reply them?
Thanks a lot.
| |
| Joshua Cranmer 2007-08-25, 7:18 pm |
| lando wrote:
> Can a Swing GUI JTextArea be used as a console ?
> I mean, can be received questions from a java program and reply them?
> Thanks a lot.
Yes it can.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
| |
|
| Joshua Cranmer ha scritto:
> lando wrote:
>
> Yes it can.
>
Can give me more details ?
Thanks.
| |
| Flo 'Irian' Schaetz 2007-08-25, 7:18 pm |
| And thus spoke lando...
>
> Can give me more details ?
Yes he can. SCNR :-)
Simply write your own PrintStream (let's call it "MyStream") that
forwards everything into the textfield and set it as your standard out
by using...
MyStream myStream = new MyStream(myTextField);
System.setOut(myStream);
The 2nd line is the important one.
Flo
| |
|
| Flo 'Irian' Schaetz ha scritto:
> And thus spoke lando...
>
>
> Yes he can. SCNR :-)
>
> Simply write your own PrintStream (let's call it "MyStream") that
> forwards everything into the textfield and set it as your standard out
> by using...
>
> MyStream myStream = new MyStream(myTextField);
> System.setOut(myStream);
>
> The 2nd line is the important one.
>
> Flo
The code I have to change is below.....and a swing GUI in the program
has already a JTextArea .......I'm rather ...
> System.out.println("Enter your JDBC/SQL query: ");
> try {
> sql = buf.readLine();
> System.out.println("You entered: " + sql);
> } catch (IOException ioe) {
> System.err.println(ioe.getMessage());
> }
| |
| Flo 'Irian' Schaetz 2007-08-25, 7:18 pm |
| And thus spoke lando...
> The code I have to change is below.....and a swing GUI in the program
> has already a JTextArea .......I'm rather ...
You want to enter some text in this JTextArea and then (probably after a
button is clicked) something should happen.
Try reading the Java Tutorials concerning JButton and ActionListener:
http://java.sun.com/docs/books/tuto...onlistener.html
| |
| z.cHris 2007-08-25, 10:17 pm |
| On Aug 26, 3:45 am, Flo 'Irian' Schaetz <ir...@gmx.de> wrote:
> And thus spoke lando...
>
>
>
> Yes he can. SCNR :-)
>
> Simply write your own PrintStream (let's call it "MyStream") that
> forwards everything into the textfield and set it as your standard out
> by using...
>
> MyStream myStream = new MyStream(myTextField);
> System.setOut(myStream);
>
> The 2nd line is the important one.
>
> Flo
PrintStream works well, and you also can add action listener to
JTextArea, when it is changed, you get the latest line as a question,
and answer it, put it to JTextArea, then, it is kind a console.
--
Chris D. Cheng
| |
| Roedy Green 2007-08-26, 4:31 am |
| On Sat, 25 Aug 2007 21:02:57 +0200, lando <""lando\"@(lando)"> wrote,
quoted or indirectly quoted someone who said :
>Can a Swing GUI JTextArea be used as a console ?
>I mean, can be received questions from a java program and reply them?
>Thanks a lot.
It is better used as a running log. Enter data in a separate
JTextField or JTextArea. Also use a JScrollPane.
See http://mindprod.com/jgloss/jtextfield.html
http://mindprod.com/jgloss/jscroller.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
| |
| Flo 'Irian' Schaetz 2007-08-26, 8:11 am |
| In-Reply-To: <1188093912.997768.237190@e9g2000prf.googlegroups.com>
X-Enigmail-Version: 0.95.3
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Lines: 12
Message-ID: <46d14f36$0$16114$9b4e6d93@newsspool1.arcor-online.net>
Organization: Arcor
NNTP-Posting-Date: 26 Aug 2007 12:00:22 CEST
NNTP-Posting-Host: 6efa4888.newsspool1.arcor-online.net
X-Trace: DXC=bK\L84954?U<<0iRN7DLEQic==]BZ:af^4Fo<]lROoRQ4nDHegD_]RU<n9D4<LcL?SHGm]1=SbW]SaK9_b<6j8@SQXf`kTMf2a]
X-Complaints-To: usenet-abuse@arcor.de
Bytes: 1791
Xref: number1.nntp.dca.giganews.com comp.lang.java.help:288642
And thus spoke z.cHris...
> PrintStream works well, and you also can add action listener to
> JTextArea, when it is changed, you get the latest line as a question,
> and answer it, put it to JTextArea, then, it is kind a console.
JTextArea has no addActionListener :-) If it was a JTextField, I would
have suggested the same, but it doesn't work in an JTextArea. A
DocumentListener would be possible, but that would be much more
complicated...
Flo
| |
| z.cHris 2007-08-26, 8:11 am |
| Flo is right:
> JTextArea has no addActionListener :-) If it was a JTextField, I would
> have suggested the same, but it doesn't work in an JTextArea. A
> DocumentListener would be possible, but that would be much more
> complicated...
>
> Flo
JTextArea tjj = new JTextArea
tjj.getDocument().addDocumentListener(new Jta());
class Jta implements DocumentListener {
public void changedUpdate(DocumentEvent e) {}
public void insertUpdate(DocumentEvent e) { ...}
public void removeUpdate(DocumentEvent e) {...}
}
...
seems complicated : )
--
Regards.
Chris D. Cheng
| |
| Flo 'Irian' Schaetz 2007-08-26, 8:11 am |
| And thus spoke z.cHris...
> seems complicated : )
No, it doesn't, because you didn't do the important work :-) If you want
to do it that way, you would have to check if the inserted character is
a Newline, then fetch the line (either by split or remembering the last
NewLine-Position), etc. That's the complicated part - at least more
complicated then a JTextField or a "Send" Button :-)
| |
|
|
|
| Flo 'Irian' Schaetz ha scritto:
> And thus spoke z.cHris...
>
>
> No, it doesn't, because you didn't do the important work :-) If you want
> to do it that way, you would have to check if the inserted character is
> a Newline, then fetch the line (either by split or remembering the last
> NewLine-Position), etc. That's the complicated part - at least more
> complicated then a JTextField or a "Send" Button :-)
It seems that you have not a code working to show .............
| |
| Flo 'Irian' Schaetz 2007-08-26, 7:19 pm |
| And thus spoke lando...
> It seems that you have not a code working to show .............
Nope, because I will not do your homework (or work) :-)
Flo
| |
| Roedy Green 2007-08-26, 10:13 pm |
| On Sun, 26 Aug 2007 15:08:28 +0200, lando <""lando\"@(lando)"> wrote,
quoted or indirectly quoted someone who said :
>
>These...don't work.......!
They work from here. Sometimes the Internet does not flow to all
corners. Give it another try.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
|
|
|