zoukankan      html  css  js  c++  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.NORTH,createNPanel());
    	 JButton start=new JButton("开始");
    	 panel.add(BorderLayout.CENTER,start);
    	 ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
             final JTextArea area = new JTextArea();
             sp.add(area);
    	 panel.add(BorderLayout.SOUTH,sp);
    	 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;
    	 }
    	 private JPanel createNPanel(){
    		 JPanel panel=new JPanel();
    		 panel.add(new JLabel("点击抽奖"),JLabel.CENTER);
    		return panel;
    	 }
    	public static void main(String[] args) {
    		new cj().setVisible(true);
    	}
    }
    

  • 相关阅读:
    硬币游戏 Project Euler 232
    屏幕空间的近似全局光照明(Approximative Global Illumination in Screen Space)
    四维之美
    vertex texture fetching in HLSL, and heightfield normal calculation
    一个VS小插件(跳出括号)
    我的算法书籍收藏
    Algorithms.算法概论.习题答案
    UML用例图教程详解
    大连理工大学软件学院博客地址
    快递查询API,我推荐“爱快递”
  • 原文地址:https://www.cnblogs.com/liangcong/p/5469087.html
Copyright © 2011-2022 走看看