它如何运作?
问题是什么? MiWIndows类未检测到子类MiOtherWindows中的更改。
问题?
如何制作一个窗口我可以不使用线程听另一个窗口?
// --------------------------------------------- ----------------------
//这里是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");
}
}
});
}
}
// --------------------------------------------- ----------------------
//这是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;
}
}
答案 0 :(得分:0)
从
更改构造函数的定义 public VentanaCrearExamen(JDialog owner)
到
public VentanaCrearExamen(MiWindows owner)
将MiWindows
的引用存储在MiWindow
:
private MiWindows owner;
.....
public VentanaCrearExamen(MiWindows owner) {
this.owner = owner;
}
在MiWindows
中定义特殊回调方法,例如
public void childActionPerformed(ActionEvent e) {
}
现在当MiWindow
中发生任何事件时,您可以将回拨方式称为MiWindows
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
this.value = "This is Result";
setVisible(false);
owner.childActionPerformed(e);
}
});
还有许多其他解决方案。我希望这篇技巧能为您提供帮助,并可能会给您其他想法。