问题
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