如何在世界风NASA中添加小部件(Textfield,Combobox等)

时间:2014-05-13 09:23:26

标签: java worldwind

我正在尝试使用world wind NASA,而不是默认选择左窗格中的图层,我想提供下拉菜单,以便我可以从中选择特定的国家/地区,然后显示内容对应于地球上的国家/地区。

那么如何添加小部件并在地球上反映相同的内容呢?

1 个答案:

答案 0 :(得分:1)

第1步:根据 worldwind要求,您需要jdk 1.6个或更多。安装诸如

jar个文件 worldwinx.jar
worldwind.jar
gdal.jar} glue-genrt.jar gluegen-rt-natives-windows-i586.jar jogl-all.jar
jogl-all-natives-windows-i586.jar
plugin.jar
vpf-symbols.jar

在您的项目 library 文件夹中根据您的 操作系统

第2步:扩展gov.nasa.worldwindx.examples.ApplicationTemplate

package yourPackageName;

import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.BasicDragger;
import gov.nasa.worldwindx.examples.ApplicationTemplate;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class YourclassName extends ApplicationTemplate
{
    public static class AppFrame extends ApplicationTemplate.AppFrame
    {
        private static JComboBox comboBox;
        private static JTextField textField;

        public AppFrame()
        {
            JPanel MainPanel = new JPanel();// new LayerPanel(this.wwjPanel.getWwd(), new Dimension(50, 50));

            GridLayout experimentLayout = new GridLayout(0,2);

            // Combobox
            JLabel labelCombo = new JLabel("Select Country");

            // Options in the combobox
            String[] options = { "India", "China", "USA", "Japan", "Russia" };
                comboBox = new JComboBox(options);
                comboBox.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                   // Do something when you select a value
                }
            });

            // Textfield
        JLabel labelTextField = new JLabel("Enter city");
         // Add controls

        textField = new JTextField();
        JPanel fieldPanel = new JPanel(experimentLayout);


        fieldPanel.add(labelCombo);
        fieldPanel.add(comboBox);
        fieldPanel.add(labelTextField);
        fieldPanel.add(textField);
        fieldPanel.add(new JButton("Go To city"));
        MainPanel.add(fieldPanel, BorderLayout.NORTH);

        this.getContentPane().add(MainPanel, BorderLayout.EAST);
    }
}
public static void main(String[] args)
{
    ApplicationTemplate.start("World Wind Example", AppFrame.class);
}
}

要在地球上反映,请制作viewcontroller并添加animator。该代码在Nasa World Wind SDK 示例中提供。

输出 World Wind Widgets