素人質問かつ莫大な質問で申し訳ないです。下記にあるコードをのプログラムをフレーム上で表示したいのですがそうなったばあいやはり最初から作り直さなくてはいけないのでしょうか。何度か試行錯誤してみたのですがなかなかうまくいきません。アドバイスなどご教授いただけたら幸いです。ちなみにこちらのコードはユーザーかコンピュターどちらかが三勝した後にグリコの配点で勝敗を決定するっものになってます。
コード package myoriject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; import java.util.Scanner; public class Janken { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] rsp = {"Rock", "Scissors", "Paper"}; System.out.print("Please enter your Name:"); String playerName = reader.readLine(); String cpuName = "Computer"; int points1 = 0; int points2 = 0; int win = 0; int lose = 0; while (win < 3 && lose < 3) { int user = getUser(); int pc = getPc(); System.out.println(playerName + ":" + rsp[user] + " || " + cpuName + ":"+ rsp[pc]); if(pc==(user+1)%3) { System.out.println("Win"); win++; points1 += (user == 0) ? 3 : 6; } else if(pc == (user+1)%3) { System.out.println("Lose"); lose++; points2 += (pc == 0) ? 3 : 6; } else { System.out.println("Drew"); } System.out.println("<RESULT> " + "WIN:" + win + " LOSE:" + lose + " <SCORE> " + playerName + ":" + points1 + " || " + cpuName + ":" + points2 ); } System.out.println("\nFinish!!!"); System.out.println("Let's Judge.........."); if( points1 < points2 ) { System.out.println("You Lose..." + " <SCORE> " + playerName + ":" + points1 + " || " + cpuName + ":" + points2 ); } else if( points2 < points1) { System.out.println("Congratulations!! You Win!!" + " <SCORE> " + playerName + ":" + points1 + " || " + cpuName + ":" + points2 ); } else if( points1 == points2 ) { System.out.println("Wow... You Drew..." + " <SCORE> " + playerName + ":" + points1 + " || " + cpuName + ":" + points2 ); } } public static int getUser() { Scanner scan = new Scanner(System.in); while(true) { //outpu massages System.out.println("\nPlease enter your choice"); System.out.print("(ROCK:0,SCISSORS:1、PAPER:2) --> "); if(scan.hasNextInt()) { int number = scan.nextInt(); if(number<=-1 || number >=3) { System.out.println("【ERROR】You can choose only 0, 1 or 2"); } else return number; } else {System.out.println("【ERROR】You can enter only the number 0, 1 or 2"); scan.next(); } } } public static int getPc() { // ready for judge Random rand = new Random(); // get a value random return rand.nextInt(3); } }
「フレーム上で表示」のフレームとは何のことでしょうか? GUI 化したいってこと?
以下の質問を見ると、SwingでのJFrameのフレームを指しているのでしょうかね。
[JFrameでのwhileの不具合] https://teratail.com/questions/9l3rxftcib7ioa
一般的に「フレームで表示したい」といきなり言われても、話は通じません。
申し訳ありません、GUIです。

回答1件
あなたの回答
tips
プレビュー