java - 将自定义组件添加到 NetBeans GUI 构建器! (世界风)

标签 java swing user-interface netbeans worldwind

好的,我正在尝试将来自 NASA 的 World Wind globe 添加到 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 对象,然后为其提供一个公共(public) 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 构建器中创建并使用 BorderLayout 作为其布局管理器的 JPanel 中。

关于java - 将自定义组件添加到 NetBeans GUI 构建器! (世界风),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481269/

相关文章:

java - 为什么 StringBufferInputStream 文档推荐使用 StringReader 进行 String 到 Stream 的转换?

java - 好的做法?虚拟对象

java - 在单独的 Eclipse 类中将 Row 添加到 DefaultTableModel

java - 在 Java 中预览和打印通用文本的独立于打印机的方式

java - PHP 中 ZipArchive 的损坏提取

java - 雅 cocoa .计算测试套件中每个测试用例的覆盖率信息

java - JComboBox 和 Action、新模型等

java - 无论我尝试什么,我的框架都是空的

JavaFX : CSS Dropdown Menu not Appearing In Netbeans IDE

java - 为什么我不能将整数转换为字符串?