java – 将自定义组件添加到NetBeans GUI构建器! (世界风)
作者:互联网
好的,我正在尝试将NASA的World Wind globe添加到NetBeans GUI builder创建的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方法,让你获得设置WorldWindowGLCanvas宾语.即,
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中,并使用BorderLayout作为其布局管理器.
标签:java,user-interface,swing,netbeans,worldwind 来源: https://codeday.me/bug/20190614/1236699.html