《java猜数字游戏源代码.pdf》由会员分享,可在线阅读,更多相关《java猜数字游戏源代码.pdf(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、importimport WindowButton extendsextends JFrame implementsimplements ActionListener/*/privateprivate staticstatic finalfinal longlongserialVersionUID=1L;intint number;JTextField inputNumber;JLabel feedBack;JButton buttonGetNumber,buttonEnter;WindowButton(String s)supersuper(猜数字小游戏);buttonGetNumber=n
2、ewnew JButton(得到一个随机数);feedBack=newnew JLabel(无反馈信息,;inputNumber=newnew JTextField(0,5);buttonEnter=newnew JButton(确定);(thisthis);(thisthis);(thisthis);Box boxH1=();(newnew JLabel(获取1-100之间的随机数:);(buttonGetNumber);Box boxH2=();(newnew JLabel(输入您的猜测:);(inputNumber);Box boxH3=();(newnew JLabel(单击确定按钮:
3、);(buttonEnter);Box boxH4=();(newnew JLabel(反馈信息:);(feedBack);Box baseBox=();(boxH1);(boxH2);(boxH3);(boxH4);Container con=getContentPane();(newnew FlowLayout();(baseBox);();setBounds(120,125,279,200);setVisible(truetrue);setDefaultCloseOperation;setBounds(100,100,150,150);setVisible(truetrue);valid
4、ate();publicpublic voidvoid actionPerformed(ActionEvent e)publicpublic classclass 猜数字游戏 publicpublic staticstatic voidvoid main(String args)newnew WindowButton(猜数字小游戏);ifif()=buttonGetNumber)elseelse ifif()=buttonEnter)intint guess=0;trytrycatchcatch(NumberFormatException event)(thisthis,请输入数字字符);guess=();ifif(guess=number)elseelse ifif(guessnumber)elseelse ifif(guessnumber)(thisthis,猜小了);(nullnull);(thisthis,猜大了);(nullnull);(thisthis,猜对了);number=(intint)()*100)+1;