彩票摇号器java代码_多线程的简单应用----彩票摇号器

效果图:

0818b9ca8b590ca3270a3433284dd417.png

package game;

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

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;

public class YaoHao extends JFrame {

Container c;

JMenuBar mb;

JMenu JFile,JHelp;

JMenuItem mExit,mCopyright;

JPanel pl;

JLabel num[]=new JLabel[6];

JButton begin,end;

boolean flag=true;

private void init(){

c=this.getContentPane();

c.setLayout(new BorderLayout());

mb=new JMenuBar();

JFile=new JMenu("文件(F)");

JHelp=new JMenu("帮助(H)");

mb.add(JFile);mb.add(JHelp);

mExit=new JMenuItem("退出(E)");

mCopyright=new JMenuItem("版权信息");

JFile.add(mExit);JHelp.add(mCopyright);

c.add(mb,BorderLayout.NORTH);

mCopyright.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

JOptionPane.showMessageDialog(null, "本游戏由暗伤无痕出品", "版权声明", JOptionPane.INFORMATION_MESSAGE);

}

});

mExit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

YaoHao.this.dispose();

}

});

pl=new JPanel();pl.setLayout(null);

c.add(pl);

for(int i=0;i<6;i++){

num[i]=new JLabel("0");

pl.add(num[i]);

num[i].setBounds((i+2)*25,30,60,30);

}

begin=new JButton("开始");

end=new JButton("结束");

pl.add(begin);pl.add(end);

begin.setBounds(220,30,60,30);

end.setBounds(290,30,60,30);

begin.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

flag=true;

Numble n=new Numble();

n.start();

}

});

end.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

Numble n=new Numble();

flag=false;

}

});

this.setSize(400,300);

this.setVisible(true);

}

public YaoHao(String title){

super(title);

init();

}

class Numble extends Thread{

Random random=new Random();

public void run(){

while(flag){

for(int i=0;i<6;i++){

num[i].setText(Integer.toString(random.nextInt(10)));

}}

try {

sleep(10000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

public static void main(String[] args) {

YaoHao yh=new YaoHao("彩票摇号器");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值