第六次

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.Random;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;

public class Cj {
JTextArea t=new JTextArea();
private Component menubar;
public static void main(String[] args) {
// TODO Auto-generated method stub
new Cj().cui();

}
public void cui(){
Panel p=new Panel();
JFrame jf=new JFrame("抽奖");
t.setBackground(Color.YELLOW);
Box a=Box.createHorizontalBox();
Box c=Box.createVerticalBox();
JButton b=new JButton("    开始");
JButton d =new JButton("取消");
A(b);


p.add(b);
p.add(d);
c.add(p);
a.add(c);
ScrollPane sp=new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
sp.add(t);
a.add(sp);
jf.add(a);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setBounds(300,300,300,300);
}

public void A(final JButton b) {
 b.addActionListener(new ActionListener() {
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 Random random = new Random();
 Object[] values = new Object[6];
 HashSet hashSet = new HashSet();

for(int i = 0;i < values.length;i++){
 int number = random.nextInt(1000) + 1;
 hashSet.add(number);
 }

values = hashSet.toArray();

t.append("一等奖为"+values[0] + "\n");
 t.append("二等奖为"+values[1]+" " +values[2]+"\n");
 t.append("三等奖为"+values[3]+" "+values[4]+" "+values[5]+"\n");
 }
 });}
}

posted on 2016-05-08 12:33  上厕所烫屁股  阅读(114)  评论(0编辑  收藏  举报