摇号程序设计
来源:互联网 发布:网络签约作者收入 编辑:程序博客网 时间:2024/04/29 02:24
编写一个摇号程序,如图所示:
要求,当单击“开始”按钮时,6个数字同时随机在0-9之间改变,每个数字都是单独变化,当单击“结束”按钮时,6个数字停止变化。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
public class YaoHao extends JFrame {
JButton sta=null;
JButton end=null;
JLabel[]shu=new JLabel[6];
Container c;
AThread[] T=new AThread[6];
public void init(){
c=this.getContentPane();
c.setLayout(new FlowLayout());
sta=new JButton("开始");
end=new JButton("结束");
//c.setBackground(Color.blue);
for(int i=0;i<6;i++){
shu[i]=new JLabel("0");
shu[i].setFont(new Font("楷体", Font.BOLD, 30));
c.add(shu[i]);
}
c.add(sta);
c.add(end);
setSize(500, 400);
setVisible(true);
sta.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
for(int i=0;i<6;i++){
T[i]=new AThread(shu[i]);
T[i].start();
}
}
});
end.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
for(int i=0;i<6;i++){
//T[i]=new AThread(shu[i]);
T[i].flag=false;
}
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public YaoHao(){
init();
}
public static void main(String[]args){
YaoHao y=new YaoHao();
}
}
class AThread extends Thread{
boolean flag=true;
JLabel shu;
public AThread(JLabel shu){
this.shu=shu;
}
public void run(){
while(flag){
int i=(int) (Math.random()*10);
shu.setText(String.valueOf(i));
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- 摇号程序设计
- 车牌摇号 程序设计题
- 北京汽车摇号
- 外卖摇号函数
- GridBagLayoutFrameDemo--摇号
- DELPHI 7 学习---------摇号
- 北京摇号日志第一章
- 摇号条件 断月也可以
- 摇号中签生成随机号
- 摇号中签生成随机号
- 北京摇号日志第二章
- 北京摇号记录第三章
- 杭州车牌摇号规则详细内容
- 自定义属性实现摇号排序
- 海淀区限价商品房第一次摇号工作统计
- 海淀区限价商品住房第一次摇号配售规则
- 利用C#写一个模拟的摇号系统
- 北京的购车摇号新政的概率分析
- P122 第21题 输入十名学生成绩 记录最高分 平均分和及格人数
- ARP数据包格式、ARP欺骗编程实现
- usage of char array which elements are mutilple STRINGs ended with a "\0"
- 排序算法
- p122第14题
- 摇号程序设计
- BC #38
- document
- IntelliJ IDEA 开发 scala 的编程环境安装
- 软件测试if else路径开源代码java中java.util.Date里面的pase方法
- 如何判断链表有环
- 足球碳分子的搭建
- hdu 1028 Ignatius and the Princess III(母函数)
- The library `xxx.jar` contains native libraries that will not run on the device.