synchronized
Hello,
Here's the situation: the user clicks a button, another JFrame starts with a table. I want the user to pick an entry there and click to confirm. The choise is passed back to the method, but the problem is that code hasn't waited for the result and ended. I tried to add wait(), but then the frame just doesn't show (more specifically a grey splotch). Maybe it's not the synchronized I should use..
Sorry, if it seems too simple, I'm new here ;)
Post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
hiwaa at 2007-7-15 3:36:30 >

Ok, here's some pseudo-code.
Basically I want relation between forms - like I can write mString = JOptionPane.showInputDialog("Message "); And it waits while user enter something, not continues. What should I use ?
public static class Select extends JFrame{
public ReturnObj create(){
//init
button.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tempObj = MysteriousFunction(table.getSelectedRow());
}
});
setVisible(true);
//(wait while tempObj is set ?)
return tempObj;
}
}
public class AnotherFrame extends JFrame {
public void create(){
//init
anotherButton.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Select select_s = new Select();
ReturnObj tObj = select_s.create();
//wait while tObj is returned ?
if (tObj != null)
//work with tObj;
}
});
}
}
Sorry but your current code design is ludicrously weird.If your application should wait a table selection from user, then you should write a listener forthat event. Your buttons seem quite redundant and useless.
hiwaa at 2007-7-15 3:36:30 >

:) maybe because it's taken from large context.. ok, no matter, did this in another way..
button was to calculate and confirm the choise from table. Just wanted to know how to make this in a nice way - there certainly is a way that one piece of code waits while another is active. But it's a bit confusing to beginner.
The calculation should be put in the table-selection-listener or a separate thread dispatched from the listener.
Remember that EDT is a single thread on which every GUI operation is done.
If your button-listener is doing something very long, for instance a very long wait, other GUI opration, including table selection, is not possible. So your code design is utterly ludicrous.
hiwaa at 2007-7-15 3:36:30 >

Ok, hiwa, thanks for help, I changed the stucture of my code. Anyway, I'm not getting excatly what I want. Let's say we have this query from user:
Person tempPerson = new Person(
new String(JOptionPane.showInputDialog("Enter Name: ")),
new String(JOptionPane.showInputDialog("Enter Surname: ")),
new String(JOptionPane.showInputDialog("Enter Location: ")));
How I should write the same, not using OptionPanes, but my own frames which return, lets say a string (or any object). I mean, then this code executes, it waits while user enters name, then surname and location, not shows three OptionPanes at once. I hope it's clear what I ask..
Hi,Have you looked at creating your own JDialog that is modal?HTH,Chris