我写了一个简单的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);
}
只是回到StackOverflow寻找其他东西,才意识到我从来没有真正回答过这个问题。对于可能正在寻找相同事物的任何人,我都会发布对我有用的东西(使用NetBeans IDE):
转到“项目”窗口(Ctrl + 1),找到要放入.jar的项目,然后右键单击它,然后单击“属性” >>“包装” >>选中所有三个框,然后单击“确定”。找到您的NetBeansProjects文件夹(默认为我相信的文档中的文件夹) )YourProject >>发行
您应该在那里看到您的.jar文件。我相信,如果有一个文件夹,则也需要包括lib文件夹,以便正确运行项目
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句