为什么我的JFrame没有出现

时间:2014-05-30 14:21:24

标签: java swing jframe

任何人都可以解释我或建议解决以下问题吗?我在eclipse工作区有两个项目,在projectA这个类运行得很好:

public class Example extends JFrame {


public Example() {
       setTitle("Simple example");
       setSize(300, 200);
       setLocationRelativeTo(null);
       setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
       Example ex = new Example();
       ex.setVisible(true);
    }

}

在projectB中,相同的代码给出了以下错误:

2014-05-30 16:18:44.885 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x000000010fff729e Java_sun_java2d_opengl_CGLLayer_nativeCreateLayer + 119
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.886 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.887 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x000000011000014c Java_sun_lwawt_macosx_CPlatformView_nativeCreateView + 169
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
    2   ???                                 0x000000010c0f0275 0x0 + 4497277557
    3   ???                                 0x000000010c0f0158 0x0 + 4497277272
)
2014-05-30 16:18:44.887 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.888 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x00000001100004e4 Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow + 188
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
    2   ???                                 0x000000010c0f0275 0x0 + 4497277557
)
2014-05-30 16:18:44.889 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.897 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x0000000110005c28 Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent + 119
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.897 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.898 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x00000001100057dd Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle + 60
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
    2   ???                                 0x000000010c0f0158 0x0 + 4497277272
)
2014-05-30 16:18:44.899 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.899 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x000000011000504e Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits + 69
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.899 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.900 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x0000000110004a1f Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax + 79
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.900 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.900 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x00000001100058e7 Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets + 72
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
    2   ???                                 0x000000010c0f0333 0x0 + 4497277747
    3   ???                                 0x000000010c0f09e1 0x0 + 4497279457
)
2014-05-30 16:18:44.901 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.911 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x0000000110004390 Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon + 64
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.912 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.913 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x0000000110004159 Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents + 59
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.913 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.914 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x0000000110006e20 Java_sun_lwawt_macosx_CCursorManager_nativeGetCursorPosition + 66
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
)
2014-05-30 16:18:44.914 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2014-05-30 16:18:44.914 java[26656:507] Cocoa AWT: Running on AppKit thread 0 when not expected. (
    0   liblwawt.dylib                      0x000000011000504e Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits + 69
    1   ???                                 0x000000010c0fbf90 0x0 + 4497325968
    2   ???                                 0x000000010c0f0158 0x0 + 4497277272
    3   ???                                 0x000000010c0f0158 0x0 + 4497277272
)
2014-05-30 16:18:44.915 java[26656:507]     Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.

在那个projectB我有很多其他类,都有正确的Java代码,其中一些主管运行得很好。但是,同样,在projectB中,如果我尝试运行代码,在现有主要内部(在没有摆动代码的情况下运行良好)中运行一些非常基本的摇摆窗口,它将运行应用程序,但我的JFrame赢了&#39 ;出现。

1 个答案:

答案 0 :(得分:0)

import javax.swing.JFrame;

public class Example extends JFrame {

    public Example() {
       this.setTitle("Simple example");
       this.setSize(300, 200);
       this.setLocationRelativeTo(null);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
       Example ex = new Example();
       ex.setVisible(true);
    }
}

我们在这里做的是扩展JFrame。示例IS-JFrame的子类,现在继承了它的所有功能。然后我们可以在构造函数方法(Example())中使用JFrame及其超类中定义的setter方法,使用'this'来显式引用当前示例的当前实例。

有关'this'的信息,请参阅此处。