找传奇、传世资源到传世资源站!
Java 正文

java_抽奖实例源码下载_

  • 资源分类:Java
  • 发 布 人:房东的猫
  • 文件大小:2915041
  • 文件格式:.rar
  • 浏览次数:21
  • 下载次数: 0
  • 发布时间:9月24日

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

/**
 * 
 */
package commtest;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.ListIterator;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jvnet.substance.skin.SubstanceAutumnLookAndFeel;








/**
 * @author Administrator
 *
 */
public class Yetptest extends JFrame implements ActionListener,Runnable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Yetptest().display3();
		
	}     

	 JFrame jf,jf1,jf2,jf3,jf4;
	 JTextArea jta,jta1,jta2;
	 JScrollPane s,s1;
	 JFileChooser jFile;
	 JButton button1, button2, button3,button4, button5, button6,button7,button8,button9;
	 JPanel jp,jp1,jp2,jp3,jp4,jp5,jp6,jp7,jp8,jp9,jp10,jp11,jp12,jp13;
	 JLabel jlb,jlb2,jlb3,jlb4,jlb5,jlb6,jlb7,jlb8,jlb9,jlb10,jlb11,jlb12,jlb13,jlb14,jlb15;
	 JLabel jt1;
	 ImageIcon ico;
	 JFileChooser jfc;
	 List list=new ArrayList();
	 List list1=new ArrayList();
	 Thread t,t1;
	 String str1;
	 JMenuBar jm1;
	 JMenu ju1,ju2;
	 JMenuItem jmt1;
	 JMenuItem jmt2, jmt3, jmt4, jmt5, jmt6, jmt7;
	 private boolean option = false;
	 Dialog d1;
	 String inputValue,add;
	 
	 boolean panduan=true;
	 boolean panduan1=true;
	 
	public Yetptest(){}
	
public void display3(){
		try {
			 UIManager.setLookAndFeel(new SubstanceAutumnLookAndFeel()); 
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		  System.out.println(add);
		  jf=new JFrame("CSDN-幸运抽奖");
		  jf.setBounds(150, 2, 1024, 768);
		  jf.setResizable(false);
			jf.setLayout(null);
		  jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		  jm1=new JMenuBar();
			ju1=new JMenu("请先点我");
		  ju1.setFont(new Font("黑体",Font.PLAIN,16));
			ju2=new JMenu("软件帮助");
			
			jmt1 =new JMenuItem("添加主办方信息");
			jmt1.addActionListener(this);
			jmt2 =new JMenuItem("添加抽奖名单数据");
			jmt2.addActionListener(this);
			jmt3 =new JMenuItem("关于我们");
			jmt3.addActionListener(this);
			jmt4 =new JMenuItem("联系我们");
			jmt4.addActionListener(this);
			jmt5 =new JMenuItem("操作帮助");
			jmt5.addActionListener(this);
			jmt6 =new JMenuItem("查询获奖名单");
			jmt6.addActionListener(this);
			jmt7 =new JMenuItem("查询往昔活动");
			jmt7.addActionListener(this);
			
			  ju1.addSeparator();
				ju1.add(jmt1);
				ju1.addSeparator();
				ju1.add(jmt2);
				ju1.addSeparator();
				ju1.add(jmt6);
				ju1.addSeparator();
				ju2.addSeparator();
				ju2.add(jmt3);
				ju2.addSeparator();
				ju2.add(jmt4);
				ju2.addSeparator();
				ju2.add(jmt5);
	      ju2.addSeparator();
				
		    jm1.add(ju1);
				jm1.add(ju2);
			
				URL url1 = Thread.currentThread().getContextClassLoader().getResource("image/login1.png");
				URL url2 = Thread.currentThread().getContextClassLoader().getResource("image/mm.png");
				URL url3 = Thread.currentThread().getContextClassLoader().getResource("image/13.png"); 
				URL url4 = Thread.currentThread().getContextClassLoader().getResource("image/12.png"); 	
				URL url5 = Thread.currentThread().getContextClassLoader().getResource("image/11.png");
				URL url6 = Thread.currentThread().getContextClassLoader().getResource("image/a.gif"); 	
				
			jp=new JPanel(null);
			jp.setBounds(0, 0, 1024, 54);
			
			
			
			jp1=new JPanel(new BorderLayout());
			jp1.setBounds(0, 140, 1024, 200);
			
			jp2=new JPanel();
			jp2.setBounds(0, 330, 1024,90);
			
			jp3=new JPanel();
			jp3.setLayout(null);
			jp3.setBounds(0, 430, 1024,80);
			
			jp4=new JPanel();
			jp4.setLayout(null);
			jp4.setBounds(0, 500, 1024,80);
			
			jp5=new JPanel();
			jp5.setBounds(0, 625, 1024,40);
			
			jp10=new JPanel();
			jp10.setLayout(null);
			jp10.setBounds(0, 350, 1024,80);
			
			jp11=new JPanel();
			jp11.setBounds(0, 60, 1024,80);
			
			jp12=new JPanel(new BorderLayout());
		  jp12.setBounds(0, 660, 1000,80);
			if(panduan==true){
			jlb8=new JLabel("请在“先点我”处添加活动标题");
			}else{
				jlb8=new JLabel(add);
			}
			
			jlb8.setForeground(new Color(139,0,0));
		  jlb8.setFont(new Font("华文行楷",Font.PLAIN,50));
			
			jlb=new JLabel(new ImageIcon(url1));
			jlb.setBounds(140, 0, 200,54);
			jlb2=new JLabel(new ImageIcon(url2));
			
			jt1=new JLabel();
			jt1.setBounds(300, 5, 200, 30);
			jt1.setFont(new Font("黑体",Font.PLAIN,70));
			
			button1 = new JButton(new ImageIcon(url3));
			button1.setBounds(205, 10, 140, 50);
			button1.addActionListener(this);
			button1.setToolTipText("加载数据");
			button2 = new JButton(new ImageIcon(url4));
			button2.setBounds(445, 10, 140, 50);
			button2.setToolTipText("开始抽奖");
			button2.setEnabled(false);
			button2.addActionListener(this);
			button3 = new JButton(new ImageIcon(url5));
			button3.setBounds(675, 10, 140, 50);
			button3.setEnabled(false);
			button3.setToolTipText("停止抽奖");
			button3.addActionListener(this);
			button4 = new JButton(new ImageIcon(url6));
			button4.setBounds(485, 10, 60, 60);
			button4.setEnabled(false);
			button4.setToolTipText("中奖名单"); 
			button4.addActionListener(this);
			
			
			jlb3=new JLabel("天津世纪乐知有限公司");
			jlb3.setForeground(Color.black);
		  jlb3.setFont(new Font("黑体",Font.PLAIN,20));
			
		  jlb9=new JLabel("时间");
		  jlb9.setForeground(Color.black);
		  jlb9.setFont(new Font("黑体",Font.PLAIN,13));
		  jlb11=new JLabel("  开发团队:JAVA开发三剑客");
			jlb11.setForeground(Color.black);
		  jlb11.setFont(new Font("黑体",Font.PLAIN,13));
		  
		  t1 = new Thread(this);
			t1.start();
		  jlb10=new JLabel("  开发团队:JAVA开发三剑客");
			jlb10.setForeground(Color.black);
		  jlb10.setFont(new Font("黑体",Font.PLAIN,13));
		  
			jp.add(jlb,BorderLayout.WEST);
			jp11.add(jlb8,BorderLayout.CENTER);
			jp1.add(jlb2,BorderLayout.CENTER);
			jp2.add(jt1);
			jp3.add(button1);
	    jp3.add(button2);
			jp3.add(button3);
			jp4.add(button4);
			jp5.add(jlb3,BorderLayout.CENTER);
			jp12.add(jlb9,BorderLayout.EAST);
			jp12.add(jlb10,BorderLayout.WEST);
			jf.setJMenuBar(jm1);
			jf.add(jp10);
			jf.add(jp);
			jf.add(jp1);
			jf.add(jp2);
			jf.add(jp3);
			jf.add(jp4);
			jf.add(jp5);
			jf.add(jp11);
			jf.add(jp12);
			jf.setVisible(true);
	}
	
	

	 

	 public void duqushuju(){
			jfc =new JFileChooser();
			int Val =jfc.showOpenDialog(null);
			if(Val == JFileChooser.APPROVE_OPTION) 
			  {
			
			String dizhi=jfc.getSelectedFile().toString();
			BufferedReader br=null;
			StringBuilder sb=new StringBuilder();
			try {
				br=new BufferedReader(new FileReader(dizhi));
			  str1=br.readLine();
				while(str1!=null){
					sb.append(str1).append("\n");
					str1=br.readLine();
					list.add(str1);
					
				}
				br.close();
				
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		}
		@Override
		public void run() {
			
			
				// TODO Auto-generated method stub
				for(ListIterator<String> it = list.listIterator(); it.hasNext();){
					if(option == true){
						try{
							jt1.setText(it.next());
							t.sleep(30);
							if(!it.hasNext()) it = list.listIterator();
						}catch(Exception e){
						
						}
					}else{
						break;
					}
				}
				
			
				// TODO Auto-generated method stub		
				Calendar cal=new GregorianCalendar();
				//System.out.println(cal.get(Calendar.SECOND));
				int yyyy=cal.get(Calendar.YEAR);
				int MM=cal.get(Calendar.MONTH) 1;
				int dd=cal.get(Calendar.DATE);
				int HH=cal.get(Calendar.HOUR_OF_DAY);
				int mm=cal.get(Calendar.MINUTE);
				int ss=cal.get(Calendar.SECOND);
				System.out.println(ss);
				

				while(true){
					try {
						t1.sleep(1000);
						ss =1;
						if(ss%60==0&&ss!=0){
							mm =1;
							ss=0;
						}if(mm%60==0&&HH!=0){
							HH =1;
							HH=0;
						}if(HH%24==0&&HH!=0){
							dd =1;
							HH=0;
						}
						String str=(yyyy<10?"0" yyyy:"" yyyy) "年" "" (MM<10?"0" MM:"" MM) "月" (dd<10?"0" dd:"" dd) "日" "   " (HH<10?"0" HH:"" HH) ":" (mm<10?"0" mm:"" mm) ":" (ss<10?"0" ss:"" ss);
						//this.jlb12.setText(str);

					 
						jlb9.setText(str);
						jlb11.setText(str);
						
						//new Yetptest().jlb9.setText(str);
						//System.out.println(jl.getText());
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
				
				

		}
		
		public void display2(){
		 
		  jf1=new JFrame("CSDN-幸运抽奖");
		  jf1.setLayout(null);
		  jf1.setVisible(false);
		  jf1.setBounds(150, 2, 1024, 768);
		  jf1.setResizable(false);
		  
		  
		  jp6=new JPanel();
			jp6.setLayout(null);
			jp6.setBounds(0, 0, 1024,70);
			jp7=new JPanel();
			jp7.setLayout(null);
			jp7.setBounds(0, 50, 1024,500);
			jp8=new JPanel();
			jp8.setBounds(0, 670, 1024,40);
			jp9=new JPanel();
			jp9.setLayout(null);
			jp9.setBounds(0, 570, 1024,80);
			jp13=new JPanel(new BorderLayout());
		  jp13.setBounds(0, 690, 1000,60);
			
			jlb4=new JLabel(" 获奖名单如下:恭喜 恭喜");
			jlb4.setBounds(260, 30,600, 40);
			jlb4.setForeground(new Color(175,88,239));
		  jlb4.setFont(new Font("华文行楷",Font.PLAIN,40));
		  
		  URL url9 = Thread.currentThread().getContextClassLoader().getResource("image/16.png"); 
		  URL url10 = Thread.currentThread().getContextClassLoader().getResource("image/16.png"); 
		  
		  jlb6=new JLabel(new ImageIcon(url9));
		  jlb7=new JLabel(new ImageIcon(url10));
		  jlb6.setBounds(0,70, 100, 500);
		  jlb7.setBounds(940,70, 100, 500);
			jta=new JTextArea();
			jta.setEditable(false);
		  jta.setText(list1.toString());
			jta.setLineWrap(true);
			jta.setFont(new Font("黑体",Font.PLAIN,35));
			jta.setForeground(Color.red);
	
			s=new JScrollPane(jta,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
			s.setBounds(100, 70, 840, 500);
			
			jlb11=new JLabel("  开发团队:JAVA开发三剑客");
			jlb11.setForeground(Color.black);
		  jlb11.setFont(new Font("黑体",Font.PLAIN,13));
		  
//		  panduan=false; 
//		  t1.start();
		  
		  
		  
		  jlb12=new JLabel("  开发团队:JAVA开发三剑客");
			jlb12.setForeground(Color.black);
		  jlb12.setFont(new Font("黑体",Font.PLAIN,13));
 
		  
			jlb5=new JLabel("天津世纪乐知有限公司");
			jlb5.setForeground(Color.black);
		  jlb5.setFont(new Font("黑体",Font.PLAIN,20));
		  
		  URL url7 = Thread.currentThread().getContextClassLoader().getResource("image/14.png"); 
		  URL url8 = Thread.currentThread().getContextClassLoader().getResource("image/15.png"); 
		  button8=new JButton(new ImageIcon(url7));
		  button8.setBounds(260, 15, 140, 50);
		  button8.addActionListener(this);
		  button9=new JButton(new ImageIcon(url8));
		  button9.setBounds(620, 15, 140, 50);
		  button9.addActionListener(this);
		  jp9.add(button8);
		  jp9.add(button9);
		  jp7.add(jlb6);
		  jp7.add(jlb7);
			jp6.add(jlb4);
			jp7.add(s);
			jp8.add(jlb5);
			
			jp13.add(jlb11,BorderLayout.EAST);
			jp13.add(jlb12,BorderLayout.WEST);
			
		  jf1.add(jp6);
			jf1.add(jp7);
			jf1.add(jp8);
			jf1.add(jp9);
			jf1.add(jp13);
			jf1.setVisible(true);
		 
	 }
	   
	 
	public void help(){
		
		 jf2 =new JFrame();
		 jf2.setBounds(500, 160, 380, 380);
		 jf2.setLayout(new GridLayout(1,1));
		 jlb14=new JLabel();
		 URL url12 = Thread.currentThread().getContextClassLoader().getResource("image/31.png"); 
		 jlb14=new JLabel(new ImageIcon(url12));
		 jf2.add(jlb14);
		
		
		 jf2.setVisible(true);
	}
	
	public void help2(){
		
		 jf4 =new JFrame();
		 jf4.setBounds(500, 160,380, 190);
		 jf4.setLayout(new GridLayout(1,1));
		 jlb15=new JLabel();
		 URL url13 = Thread.currentThread().getContextClassLoader().getResource("image/32.png"); 
		 jlb15=new JLabel(new ImageIcon(url13));
		 jf4.add(jlb15);
		 jf4.setVisible(true);
	}
	
	public void help3(){
		
		 jf3 =new JFrame();
		 jf3.setBounds(500, 160, 390, 180);
		 jf3.setLayout(new GridLayout(1,1));
		 jlb13=new JLabel();
		 URL url11 = Thread.currentThread().getContextClassLoader().getResource("image/21.png"); 
		 jlb13=new JLabel(new ImageIcon(url11));
		 jf3.add(jlb13);
		 jf3.setVisible(true);
	}
		
	public void id(){
		
		 jf3 =new JFrame();
		 jf3.setBounds(300, 60, 400, 600);
		 jf3.setLayout(new GridLayout(1,1));
		 jta2=new JTextArea();
		 jta2.setLineWrap(true);
		 jta2.setEditable(false);
		 jta2.setFont(new Font("黑体",Font.PLAIN,15));
		 jf3.add(jta2);
		 StringBuilder sb=new StringBuilder();
		 BufferedReader b1=null;
			try {
				b1=new BufferedReader(new FileReader("D://result.txt"));
				String a="";
				while((a=b1.readLine())!=null){
					sb.append(a).append("\n");
				}
				b1.close();
				jta2.setText(sb.toString());
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(b1!=null){
					try {
						b1.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		
		 jf3.setVisible(true);
	}
	
 public String add(){
  	 
		 inputValue = JOptionPane.showInputDialog("请输入公司举办此次活动的标题");
	   if(!inputValue.equals(null)){
	  	 jlb8.setText(inputValue);
	  	add=inputValue;

	   } 
	   panduan=false;
  	 return add;
   }
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		t = new Thread(this);
		if(e.getSource()==button4){
			
			display2();
		
			
			jf.dispose();
		StringBuilder sb=new StringBuilder();
		BufferedWriter b2=null;
		try {
				b2 = new BufferedWriter(new FileWriter("D://result.txt"));
				sb.append(list1).append("\n");
				b2.write(sb.toString());
				b2.flush();
				b2.close();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			
		} 
		if(e.getSource()==jmt2||e.getSource()==button1){
			duqushuju();
			button2.setEnabled(true);
			button3.setEnabled(true);
		}
		if(e.getSource()==button2){
			option = true;
			t.start();	
		}
		if(e.getSource()==button3){
			option = false;
			if(!jt1.getText().equals(null)){
			list1.add(jt1.getText());}
			list.remove(jt1.getText());
			button4.setEnabled(true);
			//t.stop();	
		}
		if(e.getSource()==button8){
			 display3();
			 list.add(str1);
			 
			 button2.setEnabled(true);
			 button3.setEnabled(true);
			t.start();
			 jf1.dispose();
		}
		if(e.getSource()==jmt1){
			
			add();
		   
		}
		if(e.getSource()==jmt3){
			help2();
			
		}
		if(e.getSource()==jmt4){
			 
			help3();
		}
		if(e.getSource()==jmt5){
			help();
		}
		if(e.getSource()==jmt6){
			id();
		}
		if(e.getSource()==jmt7){
			System.exit(0);
		}
		if(e.getSource()==button9){
			System.exit(0);
		}
		
	}

}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复