如何将对象传递给工具并将局部对象传递给外部的对象?我认为SwingUtilities.invokeLater对于一个Swing对象来说是不可靠的,对吧?如何将对象传递到实现并传递出本地对象?
Sensors sens = new Sensors();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
GUI application = new GUI(sens);
application.getJFrame().setVisible(true);
}
});
SMS sms = new SMS(application);
这是我试图解决这个问题,但我得到一个型GUI的无封闭情况下进行访问。必须用封闭的类型GUI实例来限定分配(例如x.new A(),其中x是GUI的一个实例)。问题。
// in main
Sensors sens = new Sensors();
GUI application = null;
SwingUtilities.invokeLater(new GUIthread(sens , application));
SMS sms = new SMS(application);
//a class inside GUI.java , but not inside GUI class
class GUIthread implements Runnable{
Sensors s;
GUI g;
public GUIthread(Sensors s , GUI g){
this.s = s;
this.g = g;
}
@Override
public void run() {
// TODO Auto-generated method stub
g = new GUI(s);
g.getJFrame().setVisible(true);
}
}
是`GUIthread`一个本地的内部类,还是单独的?编辑 – 2011-01-20 04:21:19
,抱歉让人混淆! – wizztjh 2011-01-20 05:01:07