How it works?
- Class MiWindows is responsible for running the class MiOtherWindows.
- MiOtherWindows class interacts with the user who changes their status and closes.
- Class MiWindows detects the change of value in the class MiOtherWindows.
- The Class MiWindows prints out the changes.
What is the Problem?
MiWIndows class does not detect the change in the child class MiOtherWindows.
Question?
How to make a window I can listen to another without using threads?
//——————————————————————-
//HERE IS THE CODE OF MiWindows
public class MiWindows extends JDialog {
private JButton doing = new JButton("The Button");
public MiWindows(SeconWindows owner) {
doing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object value;
try {
value = new MiOtherWindows(MiWindows.this).getValue();
if (value != null) {
System.out.println("Never Print this...");
}
} catch (Exception x) {
System.out.println("exception");
}
}
});
}
}
//——————————————————————-
//HERE IS THE CODE OF MiOtherWindows
public class MiOtherWindows extends JDialog {
private JButton close = new JButton("The Button");
private String value = null;
public MiOtherWindows(JDialog owner) {
super(owner);
//super(owner, true); modal don't work
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
this.value = "This is Result";
setVisible(false);
}
});
}
public String getValue() {
return value;
}
}
Change definition of constructor from
public VentanaCrearExamen(JDialog owner)to
public VentanaCrearExamen(MiWindows owner)Store the reference to
MiWindowsinMiWindow:Define special callback method in
MiWindows, for exampleNow when any event happens in
MiWindowyou can call call-back method toMiWindowsA lot of other solutions are also available. I hope this tip will help you and will probably give you other ideas.