我所有的示例程序都创建了一个JFrame
包含其组件所有代码的 big,而不是为组件创建单独的类,然后将这些组件添加到 big JFrame
. 这个 bigJFrame
是通过在匿名内部实例化来运行或显示的Runnable
,如下所示。
public static void main(String args[]) {
// Create the frame on the event dispatching thread.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StopWatch(); // Or any other JFrame
}
});
}
类StopWatch
实现ActionListener
。如果我将其作为类StopWatch
实现ActionListener
,Runnable
然后将其作为可运行对象传递给invokeLater
方法,会有什么不同吗?有没有其他方法可以做上面的代码?