Java - 欧洲最高山脉的交互式地图

时间:2015-12-17 17:57:29

标签: java

我正在欧洲各个国家的最高山上制作互动地图。我的目标是可以点击该国家,然后获取所有信息,并可能获得该国最高峰的图片。我目前的代码非常脏,因此我在这里寻找建议。我知道用另一种语言做起来会更容易,但我的目标是用Java做。我使用了SWT窗口并将地图上传到标签中。有没有人建议更好的上传图片方式?

感谢。

    package mtnMapEur;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.SWTResourceManager;

public class map {

    protected Shell shell;
    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
    private Text txtMeters;
    private Text txtCountryNorway;
    private Text txtHighestMountainGaldhpiggen;
    private Button btnTest;
    private Label label;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            map window = new map();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }




public void list(){



    }   /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell();
        shell.setMinimumSize(new Point(2400, 2284));
        shell.setSize(515, 479);
        shell.setText("SWT Application");
        shell.setMaximized(true);


        Label lblNewLabel = new Label(shell, SWT.NONE);
        lblNewLabel.setImage(SWTResourceManager.getImage("/Users/Hadle/Downloads/Optimized-mapEur.gif"));
        lblNewLabel.setBounds(10, -24, 1400, 900);



        btnTest = new Button(shell, SWT.NONE);
        btnTest.setBounds(615, 198, 94, 194);
        formToolkit.adapt(btnTest, true, true);
        btnTest.setText("Test");

        label = new Label(shell, SWT.NONE);
        label.setBounds(593, 10, 59, 14);
        formToolkit.adapt(label, true, true);
        label.setText("New Label");


        btnTest.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {

                    txtCountryNorway = new Text(shell, SWT.BORDER);
                    txtCountryNorway.setText("Country: Norway");
                    txtCountryNorway.setBounds(22, 112, 204, 30);
                    formToolkit.adapt(txtCountryNorway, true, true);

                    txtHighestMountainGaldhpiggen = new Text(shell, SWT.BORDER);
                    txtHighestMountainGaldhpiggen.setText("Highest Mountain: Galdhøpiggen");
                    txtHighestMountainGaldhpiggen.setBounds(22, 148, 204, 30);
                    formToolkit.adapt(txtHighestMountainGaldhpiggen, true, true);

                    txtMeters = new Text(shell, SWT.BORDER);
                    txtMeters.setText("Meters above sea level: 24xx");
                    txtMeters.setBounds(22, 184, 204, 30);
                    formToolkit.adapt(txtMeters, true, true);
            }





    });
}   
}

0 个答案:

没有答案