比方说
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 的可见性并使用另一个类获取字符串 dir? 喜欢
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();
它可以返回 boolean 值
。
此外,要从第二类中的第一个类读取变量,只需在第二个类中引用第一个类的对象并访问该变量(公共(public)或 protected ;在同一包内或从父类(super class)),例如System.out.println(firstClassObject.variableName
。希望能有所帮助。问候
关于java - 如何检测另一个jframe类的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8643562/