我需要帮助围绕这个程序构建一个GUI。
问题描述:
此代码是用java编写的。我想围绕这个简单的游戏构建一个GUI。我希望gui接收输入,也显示通常会发送到终端的内容。
我尝试过的内容:
This code is written in java. I would like to build a GUI around this simple game. I want the gui to take input, also to display what would normally be to a terminal.
What I have tried:
import java.util.Scanner;
import java.util.Random;
/* The purpose of this game is to guess the same number as the number as the computer comes up with.
* When you guess the right number your money is multiplied by your bet, when you lose you bet is take from you money.
* When your completely out of money the game ends. the point in this game is not to get into betting,
* this program was made for practice and fun only. Although if anyone reading this wants to give me money feel free (;
*/
public class Maingame {
static int money = 100;
static int userguess;
static int computernumber;
public static void main(String[] args) {
System.out.println("Welcome to Isaac's Guessing Game Attempt number two");
System.out.println("Pick a number between 1 and 10");
playgame();
}
public static void playgame() {
Scanner in = new Scanner(System.in);
userguess = in.nextInt();
computernumber = new Random().nextInt(5) + 1;
System.out.println(" Make a bet.");
Scanner bet = new Scanner(System.in);
int Bet = bet.nextInt();
int ng = 0;
if (computernumber == userguess) {
money *= Bet;
++ng;
System.out.println("Well done You guessed the right number.");
System.out.println("Your money is now £" + money + ". Don't spend it all in one place.");
System.out.println("your number of guess is " + ng + ".");
System.out.println("Make a new guess.");
} else {
money -= Bet;
++ng;
System.out.println("Oh no you guessed the wrong number.");
System.out.println("You have lost £" + Bet + ". You only have £" + money + " left.");
System.out.println("Guess again");
}
if (money >= 0) {
playgame();
} else {
System.out.println("Your out of " + "money. Game Over!!!!!!!!!!");
}
}
}