2011-06-25 51 views
4

好的,我试图从NASA添加World Wind globe到由NetBeans GUI Builder创建的GUI窗口。我的示例代码实例化了自己的窗口,并且GUI构建器会让我不编辑必要的区域以便将其放入:)我会编写自己的,但这是NetBeans平台应用程序的一部分,并且包含代码和注释我没有准备好处理呢。我不知道如何做到这一点。下面是示例代码,我想在窗口:将自定义组件添加到NetBeans GUI构建器! (WorldWind)

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); 
} 
} 
+1

这就是为什么我不使用GUI构建器......他们的“便利”通常被证明是不便的。 :) – mre

+1

是的,我听到你,但他们有点在NetBeans平台中将你引入它。 –

+1

您仍然可以使用NetBeans代码生成添加一个使用BorderLayout的容器,然后使用自定义代码将WorldWindowGLCanvas添加到BorderLayout.CENTER位置的容器中。 –

回答

4

要放大我的评论,我在想,你可以创建一个类,说叫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构建器中创建和使用的BorderLayout作为其布局管理一个JPanel。

+0

用于封装。也可以将其作为一个或多个代码生成属性进行插入,但描述起来会很尴尬。 – trashgod

+0

这是行得通的。现在与dang .dll有一个问题,但这种方法是可靠的。谢谢! –

3

而不是使用您的整个应用程序的GUI编辑器,限制了它的使用只是几个货柜的是将最受益于它,例如困难的布局。然后您的WorldWindowGLCanvas可以正常添加到您的top-level container。在这种exampleWorldWindowGLCanvas会一起出现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); 
+0

我认为你的答案与我的相关。那么,自GMTA以来,1票以上的投票,以及OP显然不会回来。 –

+0

哈哈,我回来了,我回来了。刚刚起床,需要一些时间来享受你的生日,无法编码所有的时间:)去尝试这些,回到你的几个。 –

相关问题