JAVA抽奖系统源代码.docx
《JAVA抽奖系统源代码.docx》由会员分享,可在线阅读,更多相关《JAVA抽奖系统源代码.docx(21页珍藏版)》请在冰点文库上搜索。
JAVA抽奖系统源代码
/*主界面
*MainFrame.java
*
*Createdon__DATE__,__TIME__
*/
/**
*
*@author__USER__
*/
{
/**CreatesnewformMainFrame*/
{
super(parent,modal);
initComponents();
this.setLocationRelativeTo(null);//居中显示
try
{
UIManager.setLookAndFeel(newSubstanceLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
SubstanceLookAndFeel
.setCurrentTheme(newSubstanceTerracottaTheme());
//SubstanceLookAndFeel.setSkin(newEmeraldDuskSkin());
//SubstanceLookAndFeel.setCurrentButtonShaper(new
//ClassicButtonShaper());
//SubstanceLookAndFeel.setCurrentWatermark(new
//SubstanceBubblesWatermark());
//SubstanceLookAndFeel.setCurrentBorderPainter(new
//StandardBorderPainter());
//SubstanceLookAndFeel.setCurrentGradientPainter(new
//StandardGradientPainter());//水晶蓝
//SubstanceLookAndFeel.setCurrentTitlePainter(new
//FlatTitlePainter());
}catch(Exceptione)
{
}
try
{
showPerson();
}catch(IOExceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
publicvoidshowPerson()throwsIOException
{
"/com/insigma/config/name.txt").getPath());
FileInputStreamfileInputStream=newFileInputStream(filename);
InputStreamReaderinputStreamReader=newInputStreamReader(
fileInputStream,"gbk");
BufferedReaderbufferedReader=newBufferedReader(inputStreamReader);
Stringname="";
Stringbufname="";
intkey=1;
while((name=bufferedReader.readLine())!
=null)
{
if(bufname.equals(""))
bufname=name;
else
bufname=bufname+"\n"+name;
key++;
}
}
/**Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:
DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
//GEN-BEGIN:
initComponents
//
privatevoidinitComponents()
{
setTitle("\u516c\u53f8\u5e74\u7ec8\u62bd\u5956\u7cfb\u7edf");
jLabel1.setText("\u4e00\u7b49\u5956\u83b7\u5f97\u8005\uff1a");
jLabel2.setText("\u4e8c\u7b49\u5956\u83b7\u5f97\u8005\uff1a");
jLabel3.setText("\u4e09\u7b49\u5956\u83b7\u5f97\u8005\uff1a");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);
jTextArea3.setColumns(20);
jTextArea3.setRows(5);
jScrollPane3.setViewportView(jTextArea3);
jLabel5.setText("\u62bd\u5956\u8005\u540d\u5355\uff1a");
jTextArea4.setColumns(20);
jTextArea4.setRows(5);
jScrollPane4.setViewportView(jTextArea4);
jButton1.setText("\u5f00\u59cb");
{
{
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u6682\u505c");
jButton2.setEnabled(false);
{
{
jButton2ActionPerformed(evt);
}
});
jButton3.setText("\u91cd\u7f6e");
jButton3.setEnabled(false);
{
{
jButton3ActionPerformed(evt);
}
});
jLabel6.setText("\u516c\u53f8\u5e74\u7ec8\u62bd\u5956");
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
.addGroup(
layout.createSequentialGroup()
.addGap(98,98,
98)
.addComponent(
jButton1)
.addGap(47,47,
47)
.addComponent(
jButton3)
.addGap(44,44,
44)
.addComponent(
jButton2)
.addGap(104,
104,
104))
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
.addGroup(
layout.createParallelGroup(
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
.addComponent(
jScrollPane1,
142,
.addComponent(
jLabel1))
.addPreferredGap(
14,
Short.MAX_VALUE)
.addGroup(
layout.createParallelGroup(
.addComponent(
jLabel2)
.addComponent(
jScrollPane2,
137,
.addGap(33,
33,
33)
.addGroup(
layout.createParallelGroup(
.addComponent(
jScrollPane3,
126,
.addComponent(
jLabel3)))
.addGroup(
layout.createSequentialGroup()
.addGap(108,
108,
108)
.addComponent(
jLabel6))
.addComponent(
jLabel5)
.addGroup(
layout.createSequentialGroup()
.addComponent(
jScrollPane4,
134,
.addPreferredGap(
80,
Short.MAX_VALUE)
.addComponent(
jLabel4,
116,
.addGap(122,
122,
122)))
.addPreferredGap(
.addGap(13,13,13)));
layout.setVerticalGroup(layout
.addGroup(
layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(26,26,26)
.addGroup(
layout.createParallelGroup(
.addGroup(
layout.createSequentialGroup()
.addComponent(
jLabel1)
.addPreferredGap(
.addComponent(
jScrollPane1,
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
.addComponent(
jLabel3)
.addComponent(
jLabel2))
.addPreferredGap(
.addGroup(
layout.createParallelGroup(
.addComponent(
jScrollPane3,
.addComponent(
jScrollPane2,
.addGap(28,28,28)
.addComponent(jLabel5)
.addPreferredGap(
.addGroup(
layout.createParallelGroup(
.addComponent(
jLabel4,
148,Short.MAX_VALUE)
.addComponent(
jScrollPane4,
148,Short.MAX_VALUE))
.addPreferredGap(
.addGroup(
layout.createParallelGroup(
.addComponent(jButton1)
.addGroup(
layout.createParallelGroup(
.addComponent(
jButton3)
.addComponent(
jButton2)))
.addContainerGap()));
pack();
}//
//GEN-END:
initComponents
/**
*重置事件
*@paramevt
*/
{
CommUtil.boo=false;
//重置计数器
CommUtil.firstsum=0;
CommUtil.secondsum=0;
CommUtil.thirdsum=0;
//清空抽奖框
//重置人员
try
{
showPerson();
}catch(IOExceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
/**
*暂停事件
*@paramevt
*/
{
CommUtil.boo=false;
}
/**
*开始事件
*@paramevt
*/
{
CommUtil.boo=true;
CardThreadcardthread=newCardThread(this);
cardthread.start();
ImageThreadimageThread=newImageThread(this);
imageThread.start();
newThread(cardthread).start();
newThread(cardthread).start();
newThread(cardthread).start();
newThread(cardthread).start();
}
/**
*@paramargsthecommandlinearguments
*/
publicstaticvoidmain(Stringargs[])
{
{
publicvoidrun()
{
{
{
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
//GEN-BEGIN:
variables
//Variablesdeclaration-donotmodify
//Endofvariablesdeclaration//GEN-END:
variables
}
抽奖功能:
publicclassCardThreadextendsThread
{
privateMainFramemainframe;
publicCardThread(MainFramemainframe)
{
this.mainframe=mainframe;
}
publicvoidrun()
{
synchronized(mainframe)
{
firstCard();
secondCard();
thirdCard();
}
if(CommUtil.isEnd())
{
}
}
/**
*抽一等奖
*/
publicvoidfirstCard()
{
while(CommUtil.boo&&CommUtil.firstsum{
intkey=(int)(Math.random()*60+1);
if(CommUtil.getPerson(key))
{
{
+"\n"+name);
}else
{
}
CommUtil.deletePerson(key);
Stringbufname=CommUtil.mapToString();
CommUtil.firstsum++;
try
{
sleep(1000);
}catch(InterruptedExceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}
/**
*抽三等奖
*/
publicvoidthirdCard()
{
while(CommUtil.boo&&CommUtil.thirdsum