最新java抽奖程序源码及心得.docx

上传人:1595****071 文档编号:35032231 上传时间:2022-08-20 格式:DOCX 页数:15 大小:136.09KB
返回 下载 相关 举报
最新java抽奖程序源码及心得.docx_第1页
第1页 / 共15页
最新java抽奖程序源码及心得.docx_第2页
第2页 / 共15页
点击查看更多>>
资源描述

《最新java抽奖程序源码及心得.docx》由会员分享,可在线阅读,更多相关《最新java抽奖程序源码及心得.docx(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-datejava抽奖程序源码及心得java抽奖程序源码及心得java抽奖程序源码及心得代码package liangmiao;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.util.*;import java.util.Timer;import java.io.*;clas

2、s 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 lm

3、ChouJiang() / 读取学生信息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) / 每一行区分的标识符是空格St

4、ringTokenizer 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); ca

5、tch (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

6、(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() in

7、t 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 implem

8、ents 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

9、 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) this.name = name;public int getNum() return num;public void setNum(int num) this.num = num;public Student(String name, int num) this.name = name;this.num = num;public void print() System.out.println(num + + name);public class choujiang public static void main(String args) lmChouJiang cj = new lmChouJiang();-

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 成人自考

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁