• 《JAVA高级程序设计》第六周作业


    import java.awt.BorderLayout;
    import java.awt.ScrollPane;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.HashSet;
    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 cj extends JFrame{
    public cj(){
    this.setTitle("抽奖系统");
    this.setSize(250, 180);
    this.setResizable(false);
    this.setLocationRelativeTo(this);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setContentPane(createContentPanel());
    }
    private JPanel createContentPanel(){
    JPanel panel=new JPanel(new BorderLayout());
    panel.add(BorderLayout.CENTER,createCeterPanel());
    return panel;
    }

     private JPanel createCeterPanel(){
    	 JPanel panel=new JPanel();
    	 panel.add(new JLabel("点击抽奖"),JLabel.CENTER);
    	 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
    			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();
    			   
    			   area.append("一等奖号码为:"+values[0] + "
    ");
    			   area.append("二等奖号码为:"+values[1]+" " +values[2]+"
    ");
    			   area.append("二等奖号码为:"+values[3]+" "+values[4]+" "+values[5]+"
    ");
    		}
    	});
    	 return panel;
    	 }
    public static void main(String[] args) {
    	new cj().setVisible(true);
    }
    

    }

  • 相关阅读:
    The Tower of Hanoi
    POJ 3259:Wormholes
    第二数学归纳法
    Josephus Problem
    想成为Java高手的25个学习目标
    How to find a cycle of length 4?
    Fabonacci Numbers
    通过参数离线安装SharePoint 2010[转]
    Sharepoint2010文档库权限问题
    BizTalk 2010 学习笔记——第一章 BizTalk 2010 概述
  • 原文地址:https://www.cnblogs.com/katne1995/p/5469258.html
Copyright © 2020-2023  润新知