讓可見說如何檢測另一個JFrame類
public class Dirchooser extends JFrame {
protected String dir;
...
private AbstractAction getGetDirAction() {
if (getDirAction == null) {
getDirAction = new AbstractAction("OK", null) {
public void actionPerformed(ActionEvent evt) {
dir = dirPathTextField1.getText();
setVisible(false);}};}
return getDirAction;}}
如何檢測Dirchooser可見,並使用另一個類得到字符串目錄? 像
public class Run {
public static void main(String[] args) throws IOException {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
inst = new DirChooser();
inst.setLocationRelativeTo(null);
inst.setVisible(true);}});
//if inst is not visible,
//sysout string dir which in inst
}
}
不確定你想知道什麼。但是如果你想檢查DirChooser是否在屏幕上可見,那麼你可以使用這個inst.isShowing();可以返回一個布爾值。此外,要從第二個類中的第一個類讀取變量,只需在第二個類中創建第一個類的Object並訪問像System.out.println(firstClassObject.variableName)這樣的變量即可。希望可以幫助。問候 – 2011-12-27 10:32:28
@ProphesyAwaits:爲什麼不把它寫成答案? – 2011-12-27 10:36:36
@HarryJoy:好的,確實會這樣做。問候 – 2011-12-27 13:03:04