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

📄 choujiang.java

📁 这个是大2时编写的一个抽奖的小程序
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/*
<applet code=choujiang width=1100 height=650>
</applet>
*/
public class choujiang extends JApplet 
                       implements ActionListener,Runnable
{
	Container cp;
	JButton start,stop;
	JPanel panel0,panel1,panel2,panel3,panel4;
	JLabel l1,l2,l3,l4;
	Font f1,f2,f3;
	byte number;
	String str;
	Thread thread1;
	boolean flag;
	public void init()
	{
		number=1;
		str="1";
		cp=getContentPane();
		thread1=new Thread(this);
		f1=new Font("Dialog",Font.BOLD,300);
		f2=new Font("Dialog",Font.ITALIC|Font.BOLD,50);
		f3=new Font("隶书",Font.BOLD,80);
		l1=new JLabel(str);
		l2=new JLabel("<html><font color=red>★爱心使者团★</font></html>");
		l3=new JLabel("<html><font color=yellow>用<br>爱<br>心<br>回<br>报<br>社<br>会</font></html>");
		l4=new JLabel("<html><font color=yellow>用<br>信<br>心<br>成<br>就<br>未<br>来</font></html>");
		l1.setFont(f1);
		l2.setFont(f3);
		l3.setFont(f2);
		l4.setFont(f2);
		panel0=new JPanel();
		panel1=new JPanel();
		panel2=new JPanel();
		panel3=new JPanel();
		panel4=new JPanel();
		start=new JButton("开始");
		stop=new JButton("停止");
		panel0.setBackground(Color.blue);
		panel1.setBackground(Color.blue);
		panel3.setBackground(Color.blue);
		panel4.setBackground(Color.blue);
		panel1.add(l1);
		panel0.add(l2);
		panel3.add(l3);
		panel4.add(l4);
		panel2.add(start);
		panel2.add(stop);
		start.addActionListener(this);
		stop.addActionListener(this);
		cp.add(panel1,"Center");
		cp.add(panel2,"South");
		cp.add(panel3,"West");
		cp.add(panel4,"East");
		cp.add(panel0,"North");
	}
	public void run()
	{
		thread1=new Thread(this);
		while(flag)
		{
			try
			{
				number=(byte)(Math.random()*120+1);
				str=str.valueOf(number);
				l1.setText(str);
				thread1.sleep(50);
			}catch(InterruptedException ie){}
		}
		
	}
		
	public void actionPerformed(ActionEvent e)
	{
		
		if(e.getSource()==start)
		{
			flag=true;
			thread1.start();
		}
		else if(e.getSource()==stop)
		{
			flag=false;
			str=str.valueOf(number);
			l1.setText(str);
		}
	}
}

⌨️ 快捷键说明

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