私は、マジック8ボールをシミュレートする単純なJavaプログラムを作成し、息子がそれを楽しんで遊ぶと考えました。私はIDEとしてNetbeansを使用していますが、プログラムをコピーして、彼が使用できる古いラップトップに置くことができるようにしたいと考えています。問題は、プログラムをコピーしてフラッシュドライブに置き、ラップトップにコピーする方法がわからないことです。
私はC ++の学習を始め、2学期の後でやめました。そして今、私は自分自身に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に作成するプロジェクトを見つけて右クリックします。プロパティ>>パッケージング>> 3つのボックスをすべてオンにして、[OK]をクリックします。NetBeansProjectsフォルダを探します(デフォルトはドキュメントにあると思います) )YourProject >> dist
そこに.jarファイルが表示されます。プロジェクトを正しく実行するためにlibフォルダーがある場合は、それも含める必要があると思います
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加