《java抽奖程序源码及心得.doc》由会员分享,可在线阅读,更多相关《java抽奖程序源码及心得.doc(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-作者xxxx-日期xxxxjava抽奖程序源码及心得【精品文档】java抽奖程序源码及心得代码package liangmiao;import .*;import .*;import .*;import .*;import ;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
2、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 Str
3、ingBuffer();String lineContent = null;String name = ;int num = 0;while (lineContent = () != null) / 每一行区分的标识符是空格StringTokenizer st = new StringTokenizer(lineContent, );/ 读取学号和姓名。每一行只有两个元素,所以I的取值就是0和1,0代表学号,1代表姓名for (int i = 0; (); i+) String word = (String) st.nextElement();if (i = 0) num = (word);
4、else name = word;Student student = new Student(name, num);(student); catch (IOException e) ();().add(, startButton);().add(, stopButton);().add(, label_num);().add(, label_name);().add(, photo);(new startlButtonListener();(new endButtonListener();();(400, 400);(true);index = 0;class MyTask extends T
5、imerTask public void run() int end = (int) () * ();for (int i = 0; i end; i+) label_num.setText(学号: + (i).getNum();(姓名: + (i).getName();index = i;();try (5); catch (Exception e) ();class startlButtonListener implements ActionListener public void actionPerformed(ActionEvent event) timer = new Timer()
6、;(new MyTask(), 0, 100);class endButtonListener implements ActionListener public void actionPerformed(ActionEvent event) ();class jPanel extends JPanel private static final long serialVersionUID = 1L;public void paintComponent(Graphics g) Image image = new ImageIcon(image/ + index + .jpg).getImage()
7、;(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) = num;public Student(String name, int num) this.name = name; = num;public void print() (num + + name);public class choujiang public static void main(String args) lmChouJiang cj = new lmChouJiang();【精品文档】