gpt4 book ai didi

java - 如何将我的 java 程序复制到另一台计算机?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:43:34 26 4
gpt4 key购买 nike

我编写了一个简单的 Java 程序来模拟一个神奇的 8 号球,我想我的儿子会喜欢玩它。我使用 Netbeans 作为我的 IDE,但我希望能够复制该程序并将其放在我让他使用的旧笔记本电脑上。问题是我不知道如何复制程序并将其放在闪存驱动器上以将其复制到他的笔记本电脑。

我开始学习 C++,第二学期后就停了,现在我决定自学 Java。在 C++ 中,我只需要将它保存为一个 .exe 文件,我就可以在任何地方运行它。我知道 java 做事的方式不同(尽管我也不完全理解该主题)并且我已经看到了类似问题的其他答案,但我想知道是否有办法将程序加载到他的计算机上他不需要编译然后运行程序。理想情况下,他只需单击桌面上的图标即可启动应用程序。

如果有帮助,我复制了下面的代码。我提前道歉,因为我从未在这里发布过问题,所以我确定我违反了某种礼节。

public static void main(String[] args) {

Random randInt = new Random();
int num = randInt.nextInt(20) + 1;
String input;
char choice = 'n';
boolean end = false;

do{
JOptionPane.showInputDialog (null, "Ask me a question. I know all things.\nWhat is your question?");
num = randInt.nextInt(20) + 1;

switch (num){

case 1 :
JOptionPane.showMessageDialog(null, "Outlook is not good.");
break;
case 2 :
JOptionPane.showMessageDialog(null, "The answer you're looking for is not in here.");
break;
case 3 :
JOptionPane.showMessageDialog(null, "Most definitely yes.");
break;
case 4 :
JOptionPane.showMessageDialog(null, "It is decidedly true.");
break;
case 5 :
JOptionPane.showMessageDialog(null, "It is certainly so.");
break;
case 6 :
JOptionPane.showMessageDialog(null, "The stars tell me it is so.");
break;
case 7 :
JOptionPane.showMessageDialog(null, "That's a stupid question. Pick another.");
break;
case 8 :
JOptionPane.showMessageDialog(null, "The answer will come to you in time.");
break;
case 9 :
JOptionPane.showMessageDialog(null, "Yes - without a doubt.");
break;
case 10 :
JOptionPane.showMessageDialog(null, "It is a certainty written in prophecy.");
break;
case 11 :
JOptionPane.showMessageDialog(null, "Chances are good.");
break;
case 12 :
JOptionPane.showMessageDialog(null, "Most likely.");
break;
case 13 :
JOptionPane.showMessageDialog(null, "Count on it.");
break;
case 14 :
JOptionPane.showMessageDialog(null, "Play the lottery instead. There is a better chance of that happening.");
break;
case 15 :
JOptionPane.showMessageDialog(null, "LOL! Absolutely not!");
break;
case 16 :
JOptionPane.showMessageDialog(null, "Not a chance");
break;
case 17 :
JOptionPane.showMessageDialog(null, "The stars are not aligned. No.");
break;
case 18 :
JOptionPane.showMessageDialog(null, "I don't know. Try asking a Ouija board.");
break;
case 19 :
JOptionPane.showMessageDialog(null, "It is so.");
break;
case 20 :
JOptionPane.showMessageDialog(null, "I'll get back to you on that.");
break;
}
input = JOptionPane.showInputDialog (null, "Would you like to ask another question? Y/N");
choice = input.charAt(0);

if (choice == 'n' || choice == 'N'){
end = true;
}
if (choice == 'y' || choice == 'Y'){
end = false;
}
else{
do{
input = JOptionPane.showInputDialog(null, "I didn't understand. Would you like to ask another question?\nPlease enter\nY for yes\nor\nN for no");
choice = input.charAt (0);
if (choice == 'n' || choice == 'N'){
end = true;
}
if (choice == 'y' || choice == 'Y'){
end = false;
}
}while (choice!='n'&& choice!='N'&&choice!='y'&&choice!='Y');
}
}while(!end);
}

最佳答案

您需要 JRE(Java 运行时环境)来运行 java 程序。如果目标计算机中有 JRE,则构建 JAR 文件。引用官方Doc .之后,您可以使用以下命令运行 jar 文件。

java -jar JarExample.jar
  1. https://docs.oracle.com/javase/tutorial/deployment/jar/build.html

关于java - 如何将我的 java 程序复制到另一台计算机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58143844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com