午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

瀏覽:167日期:2022-09-01 15:22:00

本文實(shí)例為大家分享了java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字的具體代碼,供大家參考,具體內(nèi)容如下

代碼不多說(shuō),圖片自加,實(shí)現(xiàn)功能有數(shù)字比大小,菜單開(kāi)始,幫助,退出,關(guān)于等,運(yùn)行結(jié)果如圖:

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

java實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字

代碼:

import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import java.awt.Image;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Random;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class Bingo extends JFrame implements ActionListener {JFrame frame;JMenuBar topBbr;JMenu menuQ;JMenu menuF;JMenuItem start = new JMenuItem('開(kāi)始(n)');JMenuItem out = new JMenuItem('不玩了(e)');JMenuItem help = new JMenuItem('幫助(h)');JMenuItem about = new JMenuItem('關(guān)于(a)');JPanel panelMain = new JPanel(new BorderLayout());JPanel panelNext = new JPanel(new BorderLayout());JButton btnStart;JPanel jp1, jp2, jp3, jp4;public static void main(String[] args) {new Bingo();}public Bingo() {frame = new JFrame();topBbr = new JMenuBar();frame.setTitle('王氏猜數(shù)字游戲1.0版');frame.setSize(400, 320);frame.setLocation(450, 240);frame.setLayout(getLayout());// frame.setLayout(new FlowLayout());menuQ = new JMenu('游戲(q)');menuQ.add(start);menuQ.add(out);menuF = new JMenu('幫助(f)');ImageIcon icon = new ImageIcon('imgs/logo.jpg');btnStart = new JButton(icon);JButton caiButton = new JButton('猜一猜');JButton congButton = new JButton('重新來(lái)');JTextField text = new JTextField(6);JLabel mes = new JLabel(' 請(qǐng)你輸入一個(gè)2位數(shù)');menuF.add(help);menuF.add(about);topBbr.add(menuQ);topBbr.add(menuF);frame.setJMenuBar(topBbr);panelMain.add('Center', btnStart);frame.add(panelMain);frame.setResizable(false);frame.setVisible(true);// Image im = new ImageIcon('imgs/logo.jpg').getImage();// im = im.getScaledInstance(-1, 90, DO_NOTHING_ON_CLOSE);// setIconImage(im);start.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {panelMain.setVisible(false);start.setEnabled(false);frame.add(panelNext);jp1 = new JPanel();jp2 = new JPanel(new GridLayout(2, 1));jp3 = new JPanel();JLabel top = new JLabel('??');// top.setBackground(new Color(100, 100, 0, 100));// top.setOpaque(true);JLabel jb = new JLabel(' ');JLabel jb2 = new JLabel(' ');top.setFont(new Font('隸體', Font.BOLD, 100));top.setForeground(Color.yellow);jp1.add(top);jp2.add(mes);jp2.add(text);jp3.add(caiButton);jp3.add(congButton);panelNext.add('North', jp1);panelNext.add('Center', jp2);panelNext.add('West', jb);panelNext.add('East', jb2);panelNext.add('South', jp3);panelNext.setVisible(true);}});// 開(kāi)始監(jiān)聽(tīng)1btnStart.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {start.setEnabled(false);panelMain.setVisible(false);frame.add(panelNext);jp1 = new JPanel();jp2 = new JPanel(new GridLayout(2, 1));jp3 = new JPanel();JLabel top = new JLabel('??');// top.setBackground(new Color(100, 100, 0, 100));// top.setOpaque(true);JLabel jb = new JLabel(' ');JLabel jb2 = new JLabel(' ');top.setFont(new Font('隸體', Font.BOLD, 100));top.setForeground(Color.yellow);jp1.add(top);jp2.add(mes);jp2.add(text);jp3.add(caiButton);jp3.add(congButton);panelNext.add('North', jp1);panelNext.add('Center', jp2);panelNext.add('West', jb);panelNext.add('East', jb2);panelNext.add('South', jp3);panelNext.setVisible(true);}});// 退出監(jiān)聽(tīng)out.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {frame.setVisible(false);}});// 幫助監(jiān)聽(tīng)help.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(null, '請(qǐng)按開(kāi)始進(jìn)行游戲!就是猜數(shù)字而已,就不多說(shuō)了!','幫助', JOptionPane.PLAIN_MESSAGE);}});// 關(guān)于監(jiān)聽(tīng)about.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(frame, '謝謝嘗臉試玩!', '3Q',JOptionPane.WARNING_MESSAGE);}});// 開(kāi)始監(jiān)聽(tīng)2caiButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {Random x = new Random();int y = x.nextInt(100);try {int num = Integer.parseInt(text.getText());if (num > y) {mes.setText(' 你輸入的' + num + '大了哦!');if (num > 99) {mes.setText(' 請(qǐng)輸入小于99的數(shù)字!');}}else if(num == y){mes.setText(' 恭喜你猜對(duì)了哦!');} else{mes.setText(' 你輸入的' + num + '小了哦!');if (num < 1) {mes.setText(' 請(qǐng)輸入大于0的數(shù)字!');}} } catch (Exception e2) {mes.setText(' 請(qǐng)輸入0-99的數(shù)字!');}}});// 重置監(jiān)聽(tīng)congButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {text.setText('');}});}@Overridepublic void actionPerformed(ActionEvent e) {}}

更多有趣的經(jīng)典小游戲?qū)崿F(xiàn)專題,也分享給大家:

C++經(jīng)典小游戲匯總

python經(jīng)典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經(jīng)典游戲 玩不停

java經(jīng)典小游戲匯總

javascript經(jīng)典小游戲匯總

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

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 国内精品免费视频 | 国产一区在线免费 | 一区二区欧美日韩 | 91小视频在线观看 | 天天摸日日操 | 天堂欧美城网站 | 四虎精品在线观看 | 国产精品免费在线播放 | 中文字幕不卡在线观看 | 欧美顶级毛片在线播放 | 欧美一区二区三区四区五区六区 | 亚洲国产网站 | 精品无码三级在线观看视频 | 欧美一级欧美三级在线观看 | 综合欧美日韩 | 国产伦精品一区二区三区视频网站 | 日韩视频一区二区三区在线播放免费观看 | 亚色影库 | 激情五月婷婷网 | 超碰天天| 开心激情五月婷婷 | 日本亚洲国产 | 日韩一区二区三区在线观看 | 欧美性久久久 | 国产www网站| 久久综合免费视频 | a视频在线观看 | 狠狠的干 | 中文字幕第一页在线 | 久久大胆 | 国产情侣一区二区三区 | 午夜在线网站 | 爱情岛论坛亚洲自拍 | 色婷婷亚洲 | 杨思敏毛片 | 黄色小视频免费看 | 欧美激情日韩 | 欧美一区二区免费视频 | 天天综合久久 | 狠狠干五月| 91精品国产综合久久精品图片 |