抽奖

来源:互联网 发布:美工如何压缩上传文件 编辑:程序博客网 时间:2024/06/11 01:01
  1. package WinNumber;import java.awt.BorderLayout;import java.awt.Font;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.JPanel;import javax.swing.Timer;import javax.swing.WindowConstants;@SuppressWarnings("serial")public class NameWin extends JFrame implements ActionListener {JButton bStart, bStop, bContinue;JLabel showWord;Timer time;private static final String [] LIST_NAME="吴清伟,郑建楼,叶内利,白钰琦,袁舫,杨益桦,吴威杰,林旺,林茂榜,史陈炳".split(",");Random v=new Random();public NameWin() {time = new Timer(60, this);showWord = new JLabel();showWord.setHorizontalAlignment(JLabel.CENTER);showWord.setFont(new Font("宋体", Font.BOLD, 58));bStart = new JButton("开始");bStop = new JButton("结束");bContinue = new JButton("继续");bStart.addActionListener(this);bStop.addActionListener(this);bContinue.addActionListener(this);JPanel pNorth = new JPanel();pNorth.add(bStart);pNorth.add(bStop);pNorth.add(bContinue);add(pNorth, BorderLayout.NORTH);add(showWord, BorderLayout.CENTER);setSize(300, 180);setVisible(true);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@SuppressWarnings("unused")public static void main(String[] args) {NameWin nameWin=new NameWin();}@Overridepublic void actionPerformed(ActionEvent e) {if(e.getSource()==time){int r=v.nextInt(LIST_NAME.length);showWord.setText(LIST_NAME[r]);if(r==LIST_NAME.length-1){r=0;}}else if(e.getSource()==bStart){time.start();}else if(e.getSource()==bStop){time.stop();}else if(e.getSource()==bContinue){time.restart();}}}



原创粉丝点击