D
deej21
Hello. I am making an application, and at several times the user will
need to pick an object from a list of objects. To do this, I have a
class extending JFrame that displays a JComboBox and has a button "ok"
for when the user picks the one he/she wants. But, what happens next
depends on what the user picks, so I need to wait until the user clicks
"ok" in the other JFrame.
I can't think of a way for the external JFrame to call the main one
that works. The object chosen could go one of several places, so the
easiest way is just having a method in the main JFrame that returns
whatever the user picks. However, I can't just stop in the middle of
the method and wait until "ok" is clicked. So I set it up a while loop
that calls a method in the external JFrame and checks if the button has
been clicked. It keeps going thru the loop until the button is
pressed, then retrieves the object that the user chose.
A problem with that setup is the while loop takes up all the time, and
the JFrame where the user chooses the object isn't even fully drawn.
Now, a java class, JOptionPane, does what I need to do. I was taught
to use this right when I was learning to prompt basic info from the
user. It pops up a small JFrame, and waits until info has been entered
and "ok" has been clicked. I don't know how it works though, but it
shows that it can be done.
I tried doing "Thread.currentThread().sleep(100)" but it still does
the same thing, the other JFrame isn't even drawn. I also tried
"this.wait(100)", but says that "this" is not a proper owner or
something like that.
I really need to get something like this to work - having the other
JFrame call the main one and tell it what to do will be very hard to do
in my case. Any help will be very appreciated.
need to pick an object from a list of objects. To do this, I have a
class extending JFrame that displays a JComboBox and has a button "ok"
for when the user picks the one he/she wants. But, what happens next
depends on what the user picks, so I need to wait until the user clicks
"ok" in the other JFrame.
I can't think of a way for the external JFrame to call the main one
that works. The object chosen could go one of several places, so the
easiest way is just having a method in the main JFrame that returns
whatever the user picks. However, I can't just stop in the middle of
the method and wait until "ok" is clicked. So I set it up a while loop
that calls a method in the external JFrame and checks if the button has
been clicked. It keeps going thru the loop until the button is
pressed, then retrieves the object that the user chose.
A problem with that setup is the while loop takes up all the time, and
the JFrame where the user chooses the object isn't even fully drawn.
Now, a java class, JOptionPane, does what I need to do. I was taught
to use this right when I was learning to prompt basic info from the
user. It pops up a small JFrame, and waits until info has been entered
and "ok" has been clicked. I don't know how it works though, but it
shows that it can be done.
I tried doing "Thread.currentThread().sleep(100)" but it still does
the same thing, the other JFrame isn't even drawn. I also tried
"this.wait(100)", but says that "this" is not a proper owner or
something like that.
I really need to get something like this to work - having the other
JFrame call the main one and tell it what to do will be very hard to do
in my case. Any help will be very appreciated.