我需要帮助围绕这个程序构建一个GUI。 [英] I need help building a GUI around this program.

查看:94
本文介绍了我需要帮助围绕这个程序构建一个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!!!!!!!!!!");
        }

    }
}

推荐答案

检查出来

如何使对话框(使用Java™教程>创建GUI随着JFC / Swing>使用Swing组件) [ ^ ]


这篇关于我需要帮助围绕这个程序构建一个GUI。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆