



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
java抽奖程序源码及心得代码package liangmiao;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.util.*;import java.util.Timer;import java.io.*;class lmChouJiang JFrame frame = new JFrame();JLabel label_name = new JLabel(姓名);JLabel label_num = new JLabel(学号);jPanel photo = new jPanel();JButton startButton = new JButton(开始抽奖);JButton stopButton = new JButton(结束抽奖);int index; / 保持学生信息与头像的同步ArrayList array = null; / 存储读出来的学生信息Timer timer;public lmChouJiang() / 读取学生信息array = new ArrayList();try BufferedReader bufferReader = new BufferedReader(new FileReader(student/stu2.txt);StringBuffer stringBuffer = new StringBuffer();String lineContent = null;String name = ;int num = 0;while (lineContent = bufferReader.readLine() != null) / 每一行区分的标识符是空格StringTokenizer st = new StringTokenizer(lineContent, );/ 读取学号和姓名。每一行只有两个元素,所以I的取值就是0和1,0代表学号,1代表姓名for (int i = 0; st.hasMoreElements(); i+) String word = (String) st.nextElement();if (i = 0) num = Integer.parseInt(word); else name = word;Student student = new Student(name, num);array.add(student); catch (IOException e) e.printStackTrace();frame.getContentPane().add(BorderLayout.WEST, startButton);frame.getContentPane().add(BorderLayout.EAST, stopButton);frame.getContentPane().add(BorderLayout.NORTH, label_num);frame.getContentPane().add(BorderLayout.SOUTH, label_name);frame.getContentPane().add(BorderLayout.CENTER, photo);startButton.addActionListener(new startlButtonListener();stopButton.addActionListener(new endButtonListener();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(400, 400);frame.setVisible(true);index = 0;class MyTask extends TimerTask public void run() int end = (int) (Math.random() * array.size();for (int i = 0; i end; i+) label_num.setText(学号: + String.valueOf(array.get(i).getNum();label_name.setText(姓名: + array.get(i).getName();index = i;frame.repaint();try Thread.sleep(5); catch (Exception e) e.printStackTrace();class startlButtonListener implements ActionListener public void actionPerformed(ActionEvent event) timer = new Timer();timer.scheduleAtFixedRate(new MyTask(), 0, 100);class endButtonListener implements ActionListener public void actionPerformed(ActionEvent event) timer.cancel();class jPanel extends JPanel private static final long serialVersionUID = 1L;public void paintComponent(Graphics g) Image image = new ImageIcon(image/ + index + .jpg).getImage();g.drawImage(image, 60, 100, this);class Student private String name;private int num;public String getName() return name;public void setName(String name) = name;public int getNum() return num;public void setNum(int num) this.num = num;public Student(String name, int num) = name;this.num = num;public
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年室内装饰设计师(中级)装饰施工管理试题试卷
- 2025年西式面点师(初级)实操技能考试试卷
- 2025年危险化学品安全作业特种操作证考试冲刺题试卷
- 2025年事业单位招聘考试教师地理学科专业知识押题复习试卷
- 2025年西式烹调师(初级)西餐凉菜制作技能鉴定试卷
- 2025年事业单位招聘考试计算机类专业能力测试试卷(人工智能与考古学方向)
- 2025年事业单位招聘考试教师英语学科专业知识试卷(英语教学评价标准制定)
- 2025年事业单位招聘考试综合类专业能力测试试卷(机械类)机械工程材料断裂控制试题
- 2025年事业单位招聘考试教师音乐学科专业知识试卷(音乐与历史)
- 会计制度设计A卷试题及答案
- 养生茶基础知识培训课件
- 问题解决过程PSP-完整版
- (完整版)中医适宜技术课件
- 机关、团体、企事业单位消防安全管理规定
- GB/T 20221-2023无压埋地排污、排水用硬聚氯乙烯(PVC-U)管材
- 等速肌力测试单关节或关节链不同运动模式以及运动角速度下的肌力参数
- 学生军训缓训(免训)申请表
- 真石漆施工工艺及要求【实用文档】doc
- 2017-2022年高考英语浙江卷七选五试题真题及答案汇编
- YB/T 117-1997高炉用耐火材料抗渣性试验方法
- GB/T 4744-2013纺织品防水性能的检测和评价静水压法
评论
0/150
提交评论