欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

Java

當(dāng)前位置:主頁 > 軟件編程 > Java >

Java的帶GUI界面猜數(shù)字游戲的實(shí)現(xiàn)示例

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:Java|點(diǎn)擊: 次

先導(dǎo)包

import java.util.*;
import javax.swing.*;


再寫主方法

public static void main(String[] args) {
}


新聲明一個(gè)Scanner和隨機(jī)數(shù)

public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	Random r = new Random();
}


讓UIManager爬取系統(tǒng)窗口樣式

try {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
  e.printStackTrace();
}


新建一個(gè)int類型的變量存儲(chǔ)隨機(jī)數(shù)

int secret = r.nextInt(32) + 1;

寫入主程序

JOptionPane.showMessageDialog(null, "電腦隨機(jī)生成了一個(gè)1~32之間的數(shù),請(qǐng)猜出這個(gè)數(shù)", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
String number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
int number = Integer.parseInt(number2);
while (number != secret) {
  if (number > secret) {
    JOptionPane.showMessageDialog(null, "你猜的數(shù)大了,請(qǐng)繼續(xù)猜", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
    number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
    number = Integer.parseInt(number2);
  } else {
    JOptionPane.showMessageDialog(null, "你猜的數(shù)小了,請(qǐng)繼續(xù)猜", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
    number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
    number = Integer.parseInt(number2);
  }
}
JOptionPane.showMessageDialog(null, "恭喜你,你猜對(duì)了,電腦生成的隨機(jī)數(shù)是" + secret, "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);


全部代碼

package com.demo05;

import java.util.*;
import javax.swing.*;

public class MathDemo03 {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    Random r = new Random();
    int secret = r.nextInt(32) + 1;
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }
    JOptionPane.showMessageDialog(null, "電腦隨機(jī)生成了一個(gè)1~32之間的數(shù),請(qǐng)猜出這個(gè)數(shù)", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
    String number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
    int number = Integer.parseInt(number2);
    while (number != secret) {
      if (number > secret) {
        JOptionPane.showMessageDialog(null, "你猜的數(shù)大了,請(qǐng)繼續(xù)猜", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
        number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
        number = Integer.parseInt(number2);
      } else {
        JOptionPane.showMessageDialog(null, "你猜的數(shù)小了,請(qǐng)繼續(xù)猜", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
        number2 = (String) JOptionPane.showInputDialog(null, "請(qǐng)輸入想猜的數(shù):", "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE, null, null, "");
        number = Integer.parseInt(number2);
      }
    }
    JOptionPane.showMessageDialog(null, "恭喜你,你猜對(duì)了,電腦生成的隨機(jī)數(shù)是" + secret, "猜數(shù)字游戲", JOptionPane.PLAIN_MESSAGE);
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:SpringBoot Session共享實(shí)現(xiàn)圖解

欄    目:Java

下一篇:java instanceof操作符使用及原理解析

本文標(biāo)題:Java的帶GUI界面猜數(shù)字游戲的實(shí)現(xiàn)示例

本文地址:http://mengdiqiu.com.cn/a1/Java/8791.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有