Netbeans模板AboutBox Java [英] Netbeans template AboutBox Java
问题描述
我以前在netbeans 6.9.1中使用过此代码,但在7.1.1中似乎不起作用,它在.getApplication()下划线并带有提示找不到符号".
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.
推荐答案
我通过重新安装netbeans 6.9.1找到了解决方案.似乎有一个内置库不在7.1.1中.我还发现我使用的模板是桌面应用程序"模板.
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类:
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:
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);
}
}
这篇关于Netbeans模板AboutBox Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!