Netbeans template AboutBox Java

主宰稳场 提交于 2020-01-06 20:00:01

问题


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".

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.


回答1:


Have you checked the static method getApplication() in TestProject.java? What does it show?




回答2:


I found the solution by re-installing netbeans 6.9.1. It appears that there is a built-in library that is not in 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:

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:

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);
   }
}


来源:https://stackoverflow.com/questions/9762307/netbeans-template-aboutbox-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!