好的,我正试图将NASA的世界风球添加到NetBeans GUI生成器创建的GUI窗口中。我的示例代码实例化了它自己的窗口,GUI构建器希望我不要编辑必要的区域:)我会自己写,但这是NetBeans平台应用程序的一部分,包含我还没有准备好处理的代码和注释。我不知道如何做到这一点。这是我想要的窗口中的示例代码:
public class WorldWindTest {
public static void main(String[] args) {
//create a WorldWind main object
WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
worldWindCanvas.setModel(new BasicModel());
Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);
//build Java swing interface
JFrame frame = new JFrame("World Wind");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(worldWindCanvas);
frame.setSize(800,600);
frame.setVisible(true);
//create some "Position" to build a polyline
LinkedList<Position> list = new LinkedList<Position>();
// list.add(Position.fromDegrees(i,0.0,i*20000));
}
list.add(Position.fromDegrees(30.12, -85.64, 35000));
list.add(Position.fromDegrees(31.12, -88.64, 35000));
//create "Polyline" with list of "Position" and set color / thickness
Polyline polyline = new Polyline(list);
polyline.setColor(Color.RED);
polyline.setLineWidth(3.0);
//create a layer and add Polyline
RenderableLayer layer = new RenderableLayer();
layer.addRenderable(polyline);
//add layer to WorldWind
worldWindCanvas.getModel().getLayers().add(layer);
}
}
为了进一步阐述我的评论,我想你可以创建一个类,比如SetUpWorldWindowGLCanvas,在其中初始化和设置你的WorldWindowGLCanvas对象,然后给它一个公共getter方法,让你可以获得设置好的WorldWindowGL Canvas对象。即
public class SetUpWorldWindowGLCanvas {
WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
public SetUpWorldWindowGLCanvas() {
worldWindCanvas.setModel(new BasicModel());
Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);
// ... etc
}
public WorldWindowGLCanvas getWwGlCanvas() {
return worldWindCanvas;
}
}
然后将此BorderLayout.CENTER放置在GUI生成器中创建的JPanel中,该JPanel使用BorderLayout作为布局管理器。
与其将GUI编辑器用于整个应用程序,不如将其使用限制在最能从中受益的几个容器中,例如困难的布局。然后您的WorldWindowGLCanvas
可以正常添加到您的顶级容器中。在本例中,WorldWindowGLCanvas
将与NewJPanel
:一起出现
JFrame f = new JFrame();
f.setLayout)new GridLayout(1, 0);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(worldWindCanvas);
f.add(new NewJPanel());
f.pack();
f.setVisible(true);