zoukankan      html  css  js  c++  java
  • JAVA第六次作业

    import java.awt.BorderLayout;
    
    import java.awt.ScrollPane;
    
    import java.awt.event.ActionEvent;
    
    import java.awt.event.ActionListener;
    
    import java.util.ArrayList;
    
    import java.util.HashSet;
    
    import java.util.List; 
    
    import java.util.Random;
    
    import javax.swing.JButton;
    
    import javax.swing.JFrame;
    
    import javax.swing.JLabel;
    
    import javax.swing.JPanel;
    
    import javax.swing.JTextArea;
    
     public class Draw extends JFrame{
    
     public Draw(){
    
     this.setTitle("抽奖系统");
    
     this.setSize(250, 180);
    
     this.setResizable(false);
    
     this.setLocationRelativeTo(this);
    
     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    
     this.setContentPane(createContentPanel());
    
     }
    
     private JPanel createCeterPanel(){
    
         JPanel panel=new JPanel();
    
         JButton start=new JButton("开始抽奖");
    
         panel.add(start);
    
         ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    
         final JTextArea area = new JTextArea();
    
         sp.add(area);
    
         panel.add(sp,BorderLayout.SOUTH);
    
         start.addActionListener(new ActionListener() {
    
             
    
            @Override
    
            public void actionPerformed(ActionEvent arg0) {
    
                // TODO Auto-generated method stub
    
             
    
                    double baseNum = 0.99;
    
                    String product = "矿泉水,打火机,雨伞,指甲刀";
    
                    String num = "2,2,2,1";
    
                    String[] p = product.split(",");
    
                    String[] n = num.split(",");
    
              
    
                    java.util.Random ran = new java.util.Random();
    
                    double base = ran.nextDouble();
    
              
    
                    if (base > baseNum) {
    
                        System.err.println("没中奖");
    
                        return;
    
                    }
    
              
    
                    List<String> list = new ArrayList<String>();
    
                    for (int i = 0; i < p.length; i++) {
    
                        for (int j = 0; j < Integer.parseInt(n[i]); j++) {
    
                            list.add(p[i]);
    
                        }
    
                    }
    
                            //TODO 打乱奖池数据
    
                    int l = ran.nextInt(list.size());
    
                    area.append(list.get(l));
    
              
    
                }
    
       });
    
         return panel;
    
         }
    
     private JPanel createContentPanel(){
    
     JPanel panel=new JPanel(new BorderLayout());
    
     panel.add(BorderLayout.CENTER,createCeterPanel());
    
     return panel;
    
     }
    
    public static void main(String[] args) {
    
        new Draw().setVisible(true);
    
    }
    
     
    
    }
    

  • 相关阅读:
    IP协议
    ARP协议分析
    总结struts2 iterator status的用法
    ibatis常用16条SQL语句
    Maven 项目debug调试时报Source not found.异常
    java面试题链接
    Android开发技巧一--weight属性实现视图的居中(半)显示
    Android中事件传递机制的总结
    Fragment的数据传递
    Android PopupWindow使用之地区、学校选择二级联动
  • 原文地址:https://www.cnblogs.com/blogwy/p/5498910.html
Copyright © 2011-2022 走看看