I created a class called BasicIO that had a synchronized readln()
method that did a wait(), and an event listener that would do a
notify() when the event was from the input field, but it kept giving
me an
IllegalMonitorStateException.
Obviously, I'm quite confused by threads and monitors, and was hoping
someone could enlighten me?
Thanks.
Tom A.
Of course java can. Try System.in and System.out.
> containing a jtextarea for output, and below that a jtextfield to be
> the input area. The question is, how to make the program stop and
> wait for input when it needs it.
>
Don't stop, just don't change the state you're in. Just fire an event after
the input ocurred and let the main program react on that event.
>...
> Thanks.
>
> Tom A.
Doesn't it?
<http://java.sun.com/docs/books/tutorial/essential/io/cl.html>
> so I created a jframe
JFrame
> with a jscrollpane
JScrollPane
> containing a jtextarea
JTextArea
> for output, and below that a jtextfield
JTextField
> to be
> the input area. The question is, how to make the program stop and
> wait for input when it needs it.
>
> I created a class called BasicIO that had a synchronized readln()
> method that did a wait(), and an event listener that would do a
> notify() when the event was from the input field, but it kept giving
> me an
> IllegalMonitorStateException.
Because you haven't acquired the Object's monitor.
<http://java.sun.com/javase/6/docs/api/java/lang/IllegalMonitorStateException.html>
> Obviously, I'm quite confused by threads and monitors, and was hoping
> someone could enlighten me?
<http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html>
And encompassing:
<http://java.sun.com/docs/books/tutorial/reallybigindex.html>
--
DF.
OK, to rephrase, I knew about the pre-defined input and output stream
files, but didn't want to use them, as I was under the impression that
the program would have to be running in DOS mode to have access to
them.
> > I created a class called BasicIO that had a synchronized readln()
> > method that did a wait(), and an event listener that would do a
> > notify() when the event was from the input field, but it kept giving
> > me an
> > IllegalMonitorStateException.
>
> Because you haven't acquired the Object's monitor.
> <http://java.sun.com/javase/6/docs/api/java/lang/IllegalMonitorStateEx...>
>
> > Obviously, I'm quite confused by threads and monitors, and was hoping
> > someone could enlighten me?
>
> <http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html>
>
> And encompassing:
> <http://java.sun.com/docs/books/tutorial/reallybigindex.html>
>
> --
> DF.
Thank you for the help. I'll check out those links.
Tom A.
"Files"?! "DOS"?! Say, you're a Windoze user, aren't you?
Just kidding. But you're mistaken. However, it may be that due to some
specific circumstances you might have to go the way you planned to
anyway, so go ahead.
--
DF.
>I created a class called BasicIO that had a synchronized readln()
>method that did a wait(), and an event listener that would do a
>notify() when the event was from the input field, but it kept giving
>me an
>IllegalMonitorStateException.
Events are nice discrete short things. You don't need wait etc to deal
with them. See http://mindprod.com/jgloss/event11.html
to understand how they work.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Thank you for the link. That document explained what was going on (I
think ....)
The event handling was being invoked in the EventDispatchedThread, so
it didn't have the monitor for the main program when it issued the
notify().
This seems a bit complicated to this Object Oriented programmer who
was trained when Ada was the coming thing :-)
Tom A.
Who hasn't programmed anything substantial in probably 20 years.
Damn, I feel old.
> On Aug 25, 11:36 pm, Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
> > On Mon, 25 Aug 2008 07:29:07 -0700 (PDT), "Tom A."
> > <meteoricshipya...@yahoo.com> wrote, quoted or indirectly quoted
> > someone who said :
> >
> > >I created a class called BasicIO that had a synchronized readln()
> > >method that did a wait(), and an event listener that would do a
> > >notify() when the event was from the input field, but it kept giving
> > >me an
> > >IllegalMonitorStateException.
> >
> > Events are nice discrete short things. You don't need wait etc to deal
> > with them. See http://mindprod.com/jgloss/event11.html
> > to understand how they work.
[...]
> Thank you for the link. That document explained what was going on (I
> think ....) The event handling was being invoked in the
> EventDispatchedThread, so it didn't have the monitor for the main
> program when it issued the notify().
>
> This seems a bit complicated to this Object Oriented programmer who
> was trained when Ada was the coming thing :-)
Most GUI libraries are single-threaded. Conceptually, it might help to
imagine all of Java AWT and Swing being wrapped in an Ada protected
type. Most Java GUI programs don't care; they just register methods to
listen for events and respond accordingly. Don't overlook the many
examples in the Swing tutorial:
<http://java.sun.com/docs/books/tutorial/uiswing/index.html>
> Tom A.
> Who hasn't programmed anything substantial in probably 20 years.
> Damn, I feel old.
It's a fact: learning a new language will make you feel young again. Or
at least inexperienced. :-)
Speaking of resurrecting old Pascal programs in Java, here's my
contribution:
<http://robotchase.sourceforge.net/>
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews