⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 match.java

📁 java 编程的一些简单例子
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class match extends Applet implements ActionListener
{
	Label prompt,result,bonus;
	TextField input1;
	Button btn1,btn2,btn3;
	int y=0,r=0,j=0,randomNum,n=0;
	public void init()
	{
		prompt=new Label("请输入(1-3)火柴数:");
		bonus=new Label("           Come on! ");
		input1=new TextField(5);
		btn1=new Button("You First!");
		btn2=new Button("Jsj First!");
		btn3=new Button("Go!");
		result=new Label("目前火柴数:");
		add(prompt);
		add(input1);
		add(result);
		add(btn1);
		add(btn2);
		add(btn3);
		add(bonus);
		input1.addActionListener(this);
		btn1.addActionListener(this);
		btn2.addActionListener(this);
		btn3.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e)
	{
		        y=(int)(Math.random()*40)+10;
		        result.setText("目前火柴数:"+y);
		        if(e.getSource()==btn3)
				{
					y=randomNum=(int)(Math.random()*40)+10;
			        result.setText("目前火柴数:"+y);
				}
				if(e.getSource()==btn1)
				{
					while(y>0)
					{
						if(randomNum%4==0)
						{
							r=Integer.parseInt(input1.getText());
							y-=r;
							result.setText("目前火柴数:"+y);
							j=4-r;
							y-=j;
							result.setText("目前火柴数:"+y);
						}
						if(randomNum%4!=0)
						{
							r=Integer.parseInt(input1.getText());
							y-=r;
							result.setText("目前火柴数:"+y);
							if(y%4!=0)
							{
								j=y%4;
								n++;
							}
							else							
								j=(int)(Math.random()*3)+1;							
								y-=j;
								result.setText("目前火柴数:"+y);
							
						}
					}
					if(y==0)
						bonus.setText("           You Lost!");
				}
	}
}

		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -