导航:首页 > 编程语言 > java抽奖程序

java抽奖程序

发布时间:2022-06-17 00:10:46

java代码实现抽奖:从班级的学号中抽出一个一等奖,两个二等奖,三个三等奖

抽取问题, 重点是 同一个学号不能重复被抽取.

解决办法很多,

  1. 比如数组可以使用下标来标记,号码是否被使用,使用了就继续下一次抽取

  2. 也可以使用集合来抽取,把集合顺序打乱,然后随便抽几个就可以了

参考代码:数组法

importjava.util.Random;

publicclassTest{

publicstaticvoidmain(String[]args){
intstuNums=30;

int[]nums=newint[stuNums];//存储学号的数组
boolean[]flags=newboolean[stuNums];//标记,用于标记对应下标的学号是否已经被抽取过了
for(inti=0;i<stuNums;i++){
nums[i]=i+1;//给学号赋值
}

Randomr=newRandom();
while(true){
intindex=r.nextInt(stuNums);
if(!flags[index]){
System.out.println("A等:"+nums[index]);
flags[index]=true;//标记已经被使用过了
break;
}
}


for(inti=0;i<2;i++){
intindex=r.nextInt(stuNums);
if(!flags[index]){
System.out.println("B等:"+nums[index]);
flags[index]=true;
}else{
i--;//如果已经被抽取过了,那么i建议,再次循环
}
}

for(inti=0;i<3;i++){
intindex=r.nextInt(stuNums);
if(!flags[index]){
System.out.println("c等:"+nums[index]);
flags[index]=true;
}else{
i--;
}
}
}
}

集合法

importjava.util.ArrayList;
importjava.util.Collections;

publicclassTest2{
publicstaticvoidmain(String[]args){
intstuNums=20;
ArrayList<Integer>list=newArrayList<Integer>();
for(inti=0;i<stuNums;i++){
list.add(i+1);
}

System.out.println("有序"+list);
Collections.shuffle(list);//打乱顺序
System.out.println("乱序"+list);

System.out.println("A等"+list.get(0));

System.out.println("B等"+list.get(1));
System.out.println("B等"+list.get(2));

System.out.println("C等"+list.get(3));
System.out.println("C等"+list.get(4));
System.out.println("C等"+list.get(5));
}
}

⑵ java抽奖程序

我给你个比较简单的,,但是需要按照你的要求进行稍微的修改。。然后在main方法中去执行就可以了:
public class GoodLuck {

int custNo;
int i=1;
String answer;
String awardName;
public void LuckNo(){

Scanner input=new Scanner(System.in);
System.out.println("\n我行我素购物管理系统 > 幸运抽奖\n");

do{
// 需要的话请把随机数调整成你想要的范围(我这个是为了测试方便写的1
(~3的随机数,根据你的需要把下面的3换成你想要的数字就行了)
int num=(int)(Math.random()*3+1);
System.out.print("请输入会员卡号(4位整数):");
custNo=input.nextInt();
//百位数与随机数相同的为幸运者
int =custNo/100%10;
while(i==1){
if(custNo>=1000&&custNo<=9999){
break;
}
else{
System.out.println("\n会员号码输入有误,请重新输入:");
custNo=input.nextInt();
continue;
}
}

if(==num){
showAward();
System.out.print("\n卡号:"+custNo+"是幸运客户,获得"+awardName);
}else{
System.out.print("\n卡号:"+custNo+"\t谢谢您的支持!");
}
System.out.println("\n是否继续(y/n)");
answer=input.next();
while(i==1){
if(answer.equals("y")||answer.equals("n")){
break;
}else{
System.out.print("输入有误!请重新输入:");
answer=input.next();
continue;
}
}
}while(!answer.equals("n"));

}
public void showAward(){
int num=(int)(Math.random()*3+1);
if(num==1){
awardName="Mp3";
}
else if(num==2){
awardName="美的微波炉";
}
else{
awardName="美的电饭锅";
}

}

⑶ 抽奖Java程序(是作业,急需

本来老早都给你弄好了,可你也不操心,一直没有给你发;现在就这样,需要改的话,说一下
/**
* 根据倒叙的字符串,获取与最后一位相同的位数
* @param string -倒叙后的字符串
* @return -后几位相同
*/
public static int getString( String string){
String string1 = string+"-";
//正则
String[] arr1 = string1.split(string1.toCharArray()[0]+"");
String string2 = string1.substring(0,arr1.length-1)+"-";
String[] arr2 = string2.split(string2.toCharArray()[0]+"");

return arr1.length==arr2.length?arr1.length-1:
getString(string.substring(0,arr1.length-1))
;
}

/**
* 后几位相同
* @param num
* @return
*/
public static int get(Integer num,Integer o){

String string = (num+o)+"";
StringBuffer buffer = new StringBuffer(string);
string = buffer.reverse().toString();//字符串倒叙
int count = getString(string);
return count==3&&o==0?3:
count==4&&o==0?2:
count==6&&o==0?1:
count==3&&o==1?31:
count==4&&o==1?21:
count==6&&o==1?11:
count==3&&o==-1?32:
count==4&&o==-1?22:
count==6&&o==-1?12: -1;
}

public static void main(String[] args) {
Map<String,String> map = new TreeMap<>();
Set<Integer> set = new HashSet<>();
set.add(402223);
set.add(402221);
set.add(401223);
set.add(401221);
set.add(222223);
set.add(222221);

int b = 0,n=30;
while (true){
int random = (int) (Math.random()*(1000000-100000) + 100000);
set.add(random);
if (set.size() == n){
break;
}

}

for (Integer key:set){
int count = get(key,0);
//最后一个数字是0或9的话就只有一个
count = count < 0&&key%10!=9?get(key,1):count;
count = count < 0&&key%10!=1?get(key,-1):count;
String str = count>0?(
count/10==0?(
count==3?"third":count==2?"second":"first"
)
:(
"adjacent"
)
):
"blank";
//"欢迎再来";
map.put("买到的号码:"+key, str);
}

System.out.println(map);

}

⑷ 通过java 实现 模拟抽奖

import java.util.Scanner;
public class Choujiang {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);//定义Scanner类1234
System.out.println("请输入四位卡号:");//输入提示语
int cardNo = sc.nextInt();//接受输入数据
int gewei = cardNo%10;//分解个位
int shiwei = cardNo/10%10;//分解十位
int wei = cardNo/100%10;//分解百位
int qianwei = cardNo/1000;//分解千位
int sum = gewei+shiwei+wei+qianwei;
System.out.println("会员卡号四位之和是:"+sum);
if(sum>20){//判断各位数和是否大于20
System.out.println("恭喜,你是幸运客户!");
}else{
System.out.println("谢谢惠顾!");
}
}
}

⑸ 使用java语言编写一个抽奖系统

packagech07;

importjavax.swing.*;

publicclassTest2{


publicstaticvoidmain(String[]args){
Stringoutput="";

output+="恭喜第"+(1+(int)(Math.random()*100))+"号中了一等奖";
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"号"+(int)(1+(Math.random()*100))+"号"+"中了二等奖";
for(inti=0;i<3;i++){
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"号中了三等奖";
}
JOptionPane.showMessageDialog(null,output);
}

}

程序运行结果截图

中奖的人是随机的!

⑹ java抽奖程序,可设置不同奖品获得概率

importjava.awt.EventQueue;
importjava.awt.TextArea;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.Random;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextArea;
importjavax.swing.JTextField;
importjavax.swing.border.EmptyBorder;


{

privateJPanelcontentPane;
privateJTextFieldtextFieldA;
privateJTextFieldtextFieldB;
privateJTextFieldtextFieldC;
privateTextFieldtextField;
;
privateJTextAreatextArea;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
LuckySelectframe=newLuckySelect();
frame.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}

/**
*Createtheframe.
*/
publicLuckySelect(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,251);
contentPane=newJPanel();
contentPane.setBorder(newEmptyBorder(5,5,5,5));
contentPane.setLayout(null);
setContentPane(contentPane);

JLabellblA=newJLabel("A");
lblA.setBounds(10,128,54,15);
contentPane.add(lblA);

JLabellblB=newJLabel("B");
lblB.setBounds(124,128,54,15);
contentPane.add(lblB);

JLabellblC=newJLabel("C");
lblC.setBounds(254,128,54,15);
contentPane.add(lblC);

textFieldA=newJTextField();
textFieldA.setBounds(30,125,66,21);
contentPane.add(textFieldA);
textFieldA.setColumns(10);

textFieldB=newJTextField();
textFieldB.setColumns(10);
textFieldB.setBounds(149,125,66,21);
contentPane.add(textFieldB);

textFieldC=newJTextField();
textFieldC.setColumns(10);
textFieldC.setBounds(264,125,66,21);
contentPane.add(textFieldC);

textField=newTextField();
textField.setBounds(98,167,157,21);
contentPane.add(textField);
textField.setColumns(10);

textFieldResult=newJTextField();
textFieldResult.setBounds(280,167,66,21);
contentPane.add(textFieldResult);
textFieldResult.setColumns(10);
textFieldA.setText("10");
textFieldB.setText("10");
textFieldC.setText("10");

JButtonbutton=newJButton("u62BDu5956");
button.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
select();
}
});
button.setBounds(0,166,93,23);
contentPane.add(button);

textArea=newJTextArea();
textArea.setBounds(30,31,306,83);
contentPane.add(textArea);
}

protectedvoidselect(){
//TODOAuto-generatedmethodstub
intaNum=Integer.decode(textFieldA.getText());
intbNum=Integer.decode(textFieldB.getText());
intcNum=Integer.decode(textFieldB.getText());
Randomr=newRandom();
intrandom=r.nextInt(aNum+bNum+cNum);
if(random<=aNum){
textFieldA.setText(Integer.toString(Integer.decode(textFieldA.getText())-1));
textArea.append(Integer.toString(random)+"抽中了A ");
}elseif(random<=aNum+bNum){
textFieldB.setText(Integer.toString(Integer.decode(textFieldB.getText())-1));
textArea.append(Integer.toString(random)+"抽中了B ");
}elseif(random<=aNum+bNum+cNum){
textFieldC.setText(Integer.toString(Integer.decode(textFieldC.getText())-1));
textArea.append(Integer.toString(random)+"抽中了C ");
}

}
}

⑺ 用java完成一个抽奖的程序。 每次运行程序,都会从以下的抽奖结果中随机显示一个出来:

生成100个对象,对象有个属性,其中10个是大奖,40个是小奖,50个是无奖。
放到一个List里。
每次抽中的步骤
1、随机生成0-List长度之间的数值 ,去取List中的相应对象,并移除这个对象。

代码如下。:
奖品对象类:

public class PrizeBean {

private String type;

public String getType() {
return eggType;
}

public void setType(String eggType) {
this.eggType = eggType;
}

}
奖品池初始化代码段:

{
List prizebeanList = new ArrayList();

for (int i = 0; i < 10; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(“大奖“);

prizebeanList.add(prizeBean);
}

for (int i = 0; i < 40; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(“小奖“);

prizebeanList.add(prizeBean);
}

for (int i = 0; i < 50; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(“无奖“);

prizebeanList.add(prizeBean);
}

}
抽奖代码段:

/**
*奖品池已经空的,肯定返回无奖了。。。

**/

if(prizebeanList.size()==0){
- 没有中奖哦,下次加油!
return;

}
/**
* 随机生成,奖品池中奖品数量的数字。。取出奖品池中的数字。。移除记录。返回。。
*/
int resultnum = (int) (Math.random() * prizebeanList.size());
PrizeBean resultPrizeBean = prizebeanList.get(resultnum);
prizebeanList.remove(resultPrizeBean);

if(resultPrizeBean.getType() .eqauls("大奖"){
- 恭喜,大奖!

}else if(resultPrizeBean.getType() .eqauls("小奖"){
- 运气不错哦,小奖!

}else{
- 没有中奖哦,下次加油!
}.

⑻ java 制作抽奖小程序

帮你做了一个,不知是否满意呢?

importjava.applet.Applet;

importjava.awt.Button;

importjava.awt.Color;

importjava.awt.Graphics;

importjava.awt.TextField;

importjava.awt.event.ActionEvent;

importjava.util.Random;

importjava.util.Vector;

{

=1L;

intw,h;

Buttonok,out,setup;

String[]msg;

TextField[]gaiLv;

TextField[]jiangPin;

intmx,ml;

intmaxNum;

Randomran;

Vector<Integer>fist;

Vector<Integer>sec;

Vector<Integer>third;

Vector<Integer>lucky;

booleanlot=false;

booleaniserr=false;

booleanissetup=false;

Stringmesg="输入错误";

StringpriseMsg="继续努力!";

publicvoidinit(){

w=400;

h=220;

mx=20;

ml=40;

ran=newRandom();

this.setSize(w,h);

this.setLayout(null);

ok=newButton("抽奖");

out=newButton("退出");

setup=newButton("确认设置");

msg=newString[4];

msg[0]="一等奖";

msg[1]="二等奖";

msg[2]="三等奖";

msg[3]="幸运奖";

gaiLv=newTextField[4];

jiangPin=newTextField[4];

for(inti=0;i<4;i++){

gaiLv[i]=newTextField("0.0"+(i+1));

this.add(gaiLv[i]);

gaiLv[i].setBounds(mx+ml,75+i*26,60,18);

jiangPin[i]=newTextField();

this.add(jiangPin[i]);

jiangPin[i].setBounds(mx+ml*3,75+i*26,80,18);

}

this.add(ok);

ok.setBounds(260,180,60,28);

ok.addActionListener(newLotButtonAction(this));

this.add(out);

out.setBounds(330,180,60,28);

out.addActionListener(newLotButtonAction(this));

this.add(setup);

setup.setBounds(110,180,80,24);

setup.addActionListener(newLotButtonAction(this));

}

publicvoidpaint(Graphicsg){

g.setColor(Color.white);

g.fillRect(0,0,this.getWidth(),this.getHeight());

g.setColor(newColor(230,255,230));

g.fillRect(0,0,w,30);

g.setColor(Color.BLUE);

g.drawString("JAVA抽奖系统",130,20);

g.setColor(Color.ORANGE);

g.drawRect(10,40,230,170);

g.setColor(Color.BLACK);

g.drawString("设置",mx,60);

g.drawString("概率",mx+ml,60);

g.drawString("奖品",mx+ml*3,60);

for(inti=0;i<msg.length;i++){

g.setColor(newColor(255-(i*30),45,89));

g.drawString(msg[i],20,90+i*26);

}

if(lot==true){

g.setColor(newColor(ran.nextInt(255),ran.nextInt(255),ran.nextInt(255)));

if(priseMsg.length()<=7){

g.drawString(priseMsg,260,100);

}else{

g.drawString(priseMsg.substring(0,5),260,100);

g.drawString(priseMsg.substring(5),260,120);

}

}

if(iserr==true){

g.drawString(mesg,260,100);

}

}

publicvoidgetLucky(){

floatfiru=1;

floatsecu=1;

floatthiu=1;

floatfouu=1;

floatminu=1;

if(gaiLv[0].getText().trim().length()>1){

firu=Float.parseFloat(gaiLv[0].getText());

if(firu<=0||firu>=1){

iserr=true;

return;

}

if(firu<minu){

minu=firu;

}

}

if(gaiLv[1].getText().trim().length()>1){

secu=Float.parseFloat(gaiLv[1].getText());

if(secu<=0||secu>=1){

iserr=true;

return;

}

if(secu<minu){

minu=secu;

}

}

if(gaiLv[2].getText().trim().length()>1){

thiu=Float.parseFloat(gaiLv[2].getText());

if(thiu<=0||thiu>=1){

iserr=true;

return;

}

if(thiu<minu){

minu=thiu;

}

}

if(gaiLv[3].getText().trim().length()>1){

fouu=Float.parseFloat(gaiLv[3].getText());

if(fouu<=0||fouu>=1){

iserr=true;

return;

}

if(fouu<minu){

minu=fouu;

}

}

if(minu>=1||minu<=0){

iserr=true;

return;

}

floataNum=1/minu;

maxNum=(int)aNum;

intcount=(int)(firu/minu);

if(firu!=1){

fist=getLotteryVec(maxNum,count);

}else{

fist.removeAllElements();

}

count=(int)(secu/minu);

if(secu!=1){

sec=getLotteryVec(maxNum,count);

}else{

sec.removeAllElements();

}

count=(int)(thiu/minu);

if(thiu!=1){

third=getLotteryVec(maxNum,count);

}else{

third.removeAllElements();

}

count=(int)(fouu/minu);

if(fouu!=1){

lucky=getLotteryVec(maxNum,count);

}else{

lucky.removeAllElements();

}

issetup=true;

iserr=false;

}

protectedVector<Integer>getLotteryVec(intmaxNum,intnum){

Vector<Integer>result=newVector<Integer>();

for(inti=0;i<num;i++){

result.add(ran.nextInt(maxNum));

}

returnresult;

}

protectedintgetaNum(){

returnran.nextInt(maxNum);

}

publicintisLucky(intpNum){

for(inti=0;i<fist.size();i++){

if(fist.get(i)==pNum){

return1;

}

}

for(inti=0;i<sec.size();i++){

if(sec.get(i)==pNum){

return2;

}

}

for(inti=0;i<third.size();i++){

if(third.get(i)==pNum){

return3;

}

}

for(inti=0;i<lucky.size();i++){

if(lucky.get(i)==pNum){

return4;

}

}

return-1;

}

(ActionEvente){

StringacName=e.getActionCommand();

if(acName.equals("抽奖")){

if(issetup==false){

priseMsg="请先设置参数!";

lot=true;

repaint();

lot=false;

return;

}

lot=true;

priseMsg=getResult(getaNum());

repaint();

//lot=false;

}elseif(acName.equals("退出")){

this.setVisible(false);

this.stop();

this.destroy();

System.exit(0);

}elseif(acName.equals("确认设置")){

lot=false;

getLucky();

repaint();

}

}

publicStringgetResult(intnum){

intresu=isLucky(num);

Stringresult="";

switch(resu){

case-1:

result="继续努力!";

break;

case1:

result="恭喜你!一等奖! 获得"+jiangPin[0].getText();

break;

case2:

result="恭喜你!二等奖! 获得"+jiangPin[1].getText();

break;

case3:

result="恭喜你!三等奖! 获得"+jiangPin[2].getText();

break;

case4:

result="恭喜你!幸运奖! 获得"+jiangPin[3].getText();

break;

default:

result="继续努力!";

}

returnresult+num;

}

}

.awt.event.ActionListener{

Lotterysu;

publicLotButtonAction(Lotterybun){

this.su=bun;

}

@Override

publicvoidactionPerformed(ActionEvente){

su.ButtonActionPerformed(e);

}

}

⑼ 用swing编写一个java抽奖的程序,至少有5个按钮,显得高大上一点。

&#8205;

importjava.awt.Color;//界面不是很高大上档次,但是能满足你的基本需求,希望对你有用
importjava.awt.Font;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JOptionPane;
importjavax.swing.border.Border;
importjavax.swing.border.LineBorder;
publicclass抽奖游戏extendsJFrame{
static抽奖游戏frame;
public抽奖游戏(){
setLayout(newGridLayout(3,3,3,3));
Borderborder=newLineBorder(Color.BLUE,4);
JButtonl1=newJButton();
JButtonl2=newJButton();
JButtonl3=newJButton();
JButtonl4=newJButton();
JButtonl5=newJButton();
JButtonl6=newJButton();
JButtonl7=newJButton("祝你好运");
JButtonl8=newJButton("中奖规则");
JButtonl9=newJButton("再次抽奖");
l1.setBorder(border);
l2.setBorder(border);
l3.setBorder(border);
l4.setBorder(border);
l5.setBorder(border);
l6.setBorder(border);
l7.setBorder(border);
l8.setBorder(border);
l9.setBorder(border);
String[]num2={"1","2","3","4","5","6"};
l8.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
JOptionPane.showMessageDialog(null,"游戏规则: "+"特等奖: "
+"第一行或者第二行出现的数字全部相同 "
+"第一第二行出现升序的1,2,3,4,5,6或者降序的6,5,4,3,2,1 "+"一等奖 "
+"1:第一行或第二行的数字降序排列或者升序排列 "
+"2:第一行或者第二行相邻的按钮出现一样的数字 ");
}
});
l9.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
l1.setText("*");
l2.setText("*");
l3.setText("*");
l4.setText("*");
l5.setText("*");
l6.setText("*");
l7.setBackground(Color.lightGray);
l7.setText("离中奖不远了!");
}
});
l6.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
l5.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
l4.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
l3.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
l2.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
l1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
//TODOAuto-generatedmethodstub
intj1=(int)(Math.random()*10)%6;
l1.setText(num2[j1]);
intj2=(int)(Math.random()*10)%6;
l2.setText(num2[j2]);
intj3=(int)(Math.random()*10)%6;
l3.setText(num2[j3]);
intj4=(int)(Math.random()*10)%6;
l4.setText(num2[j4]);
intj5=(int)(Math.random()*10)%6;
l5.setText(num2[j5]);
intj6=(int)(Math.random()*10)%6;
l6.setText(num2[j6]);
if(j1==j2&&j2==j3||j4==j5&&j5==j6||j1==1
&&j2==2&&j3==3&&j4==4&&j5==5&&j6==6
||j1==6&&j2==5&&j3==4&&j4==3&&j5==2
&&j6==1){
l7.setBackground(Color.red);
l7.setText("特等奖");
}elseif(j1>j2&&j2>j3||j3>j2&&j2>j1||j4>j5
&&j5>j6||j6>j5&&j5>j4||j1==j2
&&j5==j4||j1==j2&&j5==j6||j3==j2
&&j4==j5||j5==j6&&j2==j3){
l7.setBackground(Color.YELLOW);
l7.setText("一等奖");
}else{
l7.setBackground(Color.lightGray);
l7.setText("未中奖,加油!");
}
}
});
Fontfont=newFont("",Font.BOLD,20);
l1.setFont(font);
l2.setFont(font);
l3.setFont(font);
l4.setFont(font);
l5.setFont(font);
l6.setFont(font);
l7.setFont(font);
l8.setFont(font);
l9.setFont(font);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
}
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
frame=new抽奖游戏();
frame.setTitle("抽奖大战");
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

⑽ 用java写一个抽奖程序

这一百个随机数给个范围 random(范围),再分批获取呗 ,获取到的数判断在list里存在不,存在就重新获取,不存在就添加到list中去

阅读全文

与java抽奖程序相关的资料

热点内容
证据提取命令视频 浏览:353
java的学习心得 浏览:96
prof命令 浏览:279
手机加密文件密码怎么解开 浏览:283
贾跃亭程序员完整视频 浏览:958
怎样把两个文件夹打包发送 浏览:378
单片机教程资料 浏览:982
仿大众点评系统源码python 浏览:426
手机网络服务器连接不上是怎么回事 浏览:155
电脑为什么一直要解压 浏览:530
淘客优惠券网站源码 浏览:555
word转成pdf在线 浏览:775
手机暴力解压教程 浏览:130
解压小视频第二期 浏览:364
装机自带软件找不到软件文件夹 浏览:330
仙境之路服务器地址ip 浏览:708
华为服务app是什么东西 浏览:180
关于单片机的视频 浏览:592
淘宝直播app缓存怎么清理 浏览:555
android可以刷机吗 浏览:350