简体   繁体   English

Netbeans模板AboutBox Java

[英]Netbeans template AboutBox Java

I used this code previously in netbeans 6.9.1 but it does not seem to work in 7.1.1, it underlines .getApplication() with the hint "cannot find symbol". 我以前在netbeans 6.9.1中使用过此代码,但在7.1.1中似乎不起作用,它在.getApplication()下加了提示“找不到符号”。

How can I make this work again? 如何再次进行这项工作?

JFrame mainFrame = TestProject.getApplication().getMainFrame();
AboutBox newAboutBox = new  AboutBox();
newAboutBox.setLocationRelativeTo(mainFrame);
TestProject.getApplication().show(newAboutBox);

Here is a similar question, but the solution does not work. 是一个类似的问题,但是解决方案不起作用。

Have you checked the static method getApplication() in TestProject.java? 您是否在TestProject.java中检查了静态方法getApplication()? What does it show? 它显示什么?

I found the solution by re-installing netbeans 6.9.1. 我通过重新安装netbeans 6.9.1找到了解决方案。 It appears that there is a built-in library that is not in 7.1.1. 似乎有一个内置库不在7.1.1中。 I also found that the template I used was the "Desktop Application" template. 我还发现我使用的模板是“桌面应用程序”模板。

This is the solution I came up with from that: 这是我从中想到的解决方案:

TestProject class: TestProject类:

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

public class TestProject extends SingleFrameApplication {

    @Override protected void startup() {
        show(new AppView(this));
    }

    @Override protected void configureWindow(java.awt.Window root) { }

    public static TestProject getApplication() {
        return Application.getInstance(TestProject.class);
    }

    public static void main(String[] args) {
        launch(TestProject.class, args);
    }
}

AppView JFrame: AppView JFrame:

import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;

public class AppView extends FrameView {
   public AppView(SingleFrameApplication app) {
       super(app);

       JFrame mainFrame = TestProject.getApplication().getMainFrame();
       AboutBox newAboutBox = new  AboutBox();
       newAboutBox.setLocationRelativeTo(mainFrame);
       TestProject.getApplication().show(newAboutBox);
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM