如何将我的java程序下载

时间:2012-02-26 15:32:50

标签: java eclipse

我使用eclipse制作了这个java计算器和基于文本的游戏。我想要做的是有一些.exe或.jar文件或任何当我运行它运行我的java程序。我希望能够将其下载以便其他人可以在没有日食的情况下玩我的基于文本的游戏。我问的是我希望我的程序能够在浏览器或其他人的计算机上运行。 我不知道为什么你会需要它,但也许它在代码的某处,继承我的计算器代码

package calculator;
import java.util.Scanner;

public class calculator {


    public static void main(String args[]){
        Scanner test = new Scanner(System.in);
        System.out.println("enter a number");
        int a = test.nextInt();
        System.out.println("enter 1 to add 2 to subtract 3 to multiply 4 for divide");
        int t = test.nextInt();
        if(t == 1){
            System.out.println("enter the second number");
            int g = test.nextInt();
            int u = a + g;
            System.out.println("The answer is " + u);
        }
        if(t == 2){
            System.out.println("enter the second number");
            int l = test.nextInt();
            int m = a - l;
            System.out.println("The answer is " + m);
        }
        if(t == 3){
            System.out.println("enter the second number");
            int j = test.nextInt();
            int v = a * j;
            System.out.println("The answer is " + v);
        }
        if(t == 4){
            System.out.println("enter the second number");
            int p = test.nextInt();
            int z = a / p;
            System.out.println("The answer is " + z);
        }
    }
}

4 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

您需要将文件打包为可执行的JAR文件。请谷歌吧。

答案 2 :(得分:0)

据我所知,我的文章“Convert Java to EXE - Why, When, When Not and How”涵盖了所有可用选项,从可执行jar到Java Web Start,再到启动程序/包装器/安装程序,再到本机编译。

答案 3 :(得分:0)

根据我的经验,BlueJ最好用这个。

如果你使用BlueJ,这些类会灵活切换,添加它们并不是NetBeans的痛苦。

现在为BlueJ jar文件点击“Project” - >选择主类 - >我会点击包含source和BlueJ文件的两个按钮,以备日后编辑时使用(所以将所有文件保存在一起)。

你拥有它!

它相对较快,NetBeans在创建JAR文件时非常痛苦。