當前位置:首頁 » 編程語言 » java抽獎

java抽獎

發布時間: 2022-01-10 08:23:37

『壹』 抽獎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.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import java.util.*;

import java.io.FileReader;
import java.io.File;

// This example demonstrates the use of JButton, JTextField
// and JLabel.
public class LunarPhases implements ActionListener {
final static int NUM_IMAGES = 1000;

final static int START_INDEX = 0;

int REAL_NUM_IMAGES = 0;

ImageIcon[] images = new ImageIcon[NUM_IMAGES];

String[] imageNames = new String[NUM_IMAGES];

JPanel mainPanel, selectPanel, displayPanel, resultPanel;

JButton phaseChoice = null;

JLabel phaseIconLabel = null, phaseResult = null;

// Constructor
public LunarPhases() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
resultPanel = new JPanel();

// Add various widgets to the sub panels.
addWidgets();

// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1, 3, 5, 5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
mainPanel.add(resultPanel);
}

// Create and the widgets to select and display the phases of the moon.
private void addWidgets() {
// Get the images and put them into an array of ImageIcon.
File dir = new File("C:\\Program Files\\JavaSoft\\JDK1.3.1\\bin\\images");
File[] files = dir.listFiles();
String imageName = null;
String temp = null;
int j = 0;
for (int i = 0; i < files.length; i++) {
if (!files[i].isDirectory()) {
imageName = "images/" + files[i].getName();
}
temp = imageName.substring(imageName.lastIndexOf(".") + 1, imageName.length());
if(!temp.equals("gif"))
{
continue;
}
URL iconURL = ClassLoader.getSystemResource(imageName);
ImageIcon icon = new ImageIcon(iconURL);
images[j] = icon;
imageNames[j] = imageName.substring(7,imageName.lastIndexOf("."));
j++;
}
REAL_NUM_IMAGES = j;

// Create label for displaying moon phase images and put a border around
// it.
phaseIconLabel = new JLabel();
phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0, 0, 10, 0), phaseIconLabel
.getBorder()));

phaseResult = new JLabel();

// Create combo box with lunar phase choices.
phaseChoice = new JButton("開始/停止");

// Display the first image.
phaseIconLabel.setIcon(images[START_INDEX]);
phaseIconLabel.setText("");

// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Select Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

resultPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Result Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Display Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add moon phases combo box to select panel and image label to
// displayPanel.
selectPanel.setLayout(new GridLayout(3,3));//這里原來是selectPanel.add(phaseChoice);
// displayPanel.add(phaseIconLabel);
// resultPanel.add(phaseResult);

selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(phaseChoice);
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
resultPanel.setLayout(new BorderLayout());
displayPanel.add(phaseIconLabel);
resultPanel.add(phaseResult);

// Listen to events from combo box.
phaseChoice.addActionListener(this);
}

boolean run = false;
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
if(run){
run = false;
}
else{
run = true;
new Thread(){
public void run(){
while(run){
int a =(int)( Math.random()*REAL_NUM_IMAGES);
phaseIconLabel.setIcon(images[a]);
phaseResult.setText(imageNames[a]);
try{
Thread.sleep(100);
}
catch(Exception e){}
}
}
}.start();
}
}

// main method
public static void main(String[] args) {
// create a new instance of LunarPhases
LunarPhases phases = new LunarPhases();

// Create a frame and container for the panels.
JFrame lunarPhasesFrame = new JFrame("Lunar Phases");

// Set the look and feel.
try {
UIManager.setLookAndFeel(UIManager
.());
} catch (Exception e) {
}

lunarPhasesFrame.setContentPane(phases.mainPanel);

// Exit when the window is closed.
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Show the converter.
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
}

『叄』 用java寫一個抽獎程序

這一百個隨機數給個范圍 random(范圍),再分批獲取唄 ,獲取到的數判斷在list里存在不,存在就重新獲取,不存在就添加到list中去

『肆』 JAVA抽獎的演算法

那你可以再1-10000之間隨即嘛,概率小的獎品設置為1-10,概率大的設置為11-1000,最後隨即出來的數判斷一下在那個區間就可以了.
實體類,就是寫一個JAVA BEAN嘛,裡面記載獎品名字和數量啊,不懂可以追問

『伍』 用java做一個抽獎的代碼

要在cmd下運行啊 我想你安裝JDK沒?

import java.util.*;
class Test{
private int maxSize=0;
private int selectSize=0;
private List<Integer> list=new ArrayList<Integer>();
private int[] one=new int[7];
public Test(int maxSize,int selectSize){
this.maxSize=maxSize;
this.selectSize=selectSize;
one=new int[selectSize];
for(int i=1;i<=maxSize;i++)
list.add(Integer.valueOf(i));
}

public void open(){
List<Integer> temp=new ArrayList<Integer>();
temp.addAll(list);
int[] p=new int[selectSize];
int tag=0;
for(int i=0;i<selectSize;i++){
tag=(int)(Math.random()*555555%temp.size());
p[i]=(Integer)temp.get(tag).intValue();
temp.remove(tag);
}
one=p;

}
public void paixu(){
int temp=0;
for(int i=0;i<selectSize;i++){
for(int j=0;j<selectSize-1;j++){
if(one[j]>one[j+1]) {temp=one[j];one[j]=one[j+1];one[j+1]=temp;}
}
}
}

public void printOpen(){
open();
paixu();
for(int i=0;i<one.length;i++)
System.out.print(one[i]+" ");
System.out.println();
}
static public void main(String[] str){
Test t=new Test(33,6); //彩票類型:33選6
for(int i=0;i<10;i++) //開10次獎
t.printOpen();

}
}

『陸』 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的抽獎系統

用隨機的辦法 來 作為抽獎結果 是誤人的。。。。
理想辦法是生成抽獎池

然後以隨機數的辦法生成數據進入抽獎池中抽取獎品

並且加入判斷語句來過濾已經抽取出來的獎品 一直到獎池為空

『捌』 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技術實現幸運抽獎活動系統

import java.util.Scanner;
public class LuckyNumber {
/**
* 幸運抽獎
*/
public static
void main(String[] args) {
String answer
= "y"; // 標識是否繼續
String
userName = ""; // 用戶名
String
password = ""; // 密碼
int cardNumber
= 0; // 卡號
boolean
isRegister = false; // 標識是否注冊
boolean
isLogin = false; // 標識是否登錄
int max =
9999;
int min =
1000;
Scanner input
= new Scanner(System.in);
do {
System.out.println("*****歡迎進入獎客富翁系統*****");
System.out.println("\t1.注冊");
System.out.println("\t2.登錄");
System.out.println("\t3.抽獎");
System.out.println("***************************");
System.out.print("請選擇菜單:");
int choice =
input.nextInt();
switch
(choice) {
case 1:
System.out.println("[獎客富翁系統
> 注冊]");
System.out.println("請填寫個人注冊信息:");
System.out.print("用戶名:");
userName =
input.next();
System.out.print("密碼:");
password =
input.next();
//
獲取4位隨機數作為卡號
cardNumber =
(int)(Math.random()*(max-min))+min;
System.out.println("\n注冊成功,請記好您的會員卡號");
System.out.println("用戶名\t密碼\t會員卡號");
System.out.println(userName
+ "\t" + password + "\t" + cardNumber);
isRegister =
true; // 注冊成功,標志位設置為true
break;
case 2:
System.out.println("[獎客富翁系統
> 登錄]");
if
(isRegister) { // 判斷是否注冊
//
3次輸入機會
for (int i
= 1; i <= 3; i++) {
System.out.print("請輸入用戶名:");
String
inputName = input.next();
System.out.print("請輸入密碼:");
String
inputPassword = input.next();
if
(userName.equals(inputName) && password.equals(inputPassword)) {
System.out.println("\n歡迎您:"
+ userName);
isLogin =
true; // 登錄成功,標志位設置為true
break;
} else if
(i < 3) {
System.out.println("用戶名或密碼錯誤,還有"
+ (3 - i) + "次機會!");
} else
{
System.out.println("您3次均輸入錯誤!");
}
}
} else
{
System.out.println("請先注冊,再登錄!");
}
break;
case 3:
System.out.println("[獎客富翁系統
> 抽獎]");
if
(!isLogin) { // 判斷是否登錄
System.out.println("請先登錄,再抽獎!");
} else
{
//生成5個4位隨機數字,並保存在數組中
int[]
luckynums = new int[5];
for(int i
= 0; i < luckynums.length; i++){
luckynums[i] =
(int)(Math.random()*(max-min))+min;
}
System.out.print("請輸入您的卡號:");
int
yourcard = input.nextInt();
int
i;
System.out.print("\n本日的幸運數字為:");
for (i = 0;
i < luckynums.length; i++) {
System.out.print(luckynums[i]
+ " ");\
}
for (i = 0;
i < luckynums.length; i++) {
if
(luckynums[i] == yourcard) {
System.out.println("\n恭喜!您是本日的幸運會員!");
break;
}
}

if (i ==
luckynums.length) {
System.out.println("\n抱歉!您不是本日的幸運會員!");
}
}
break;
default:
System.out.println("[您的輸入有誤!]");
break;
}
System.out.print("繼續嗎?(y/n):");
answer =
input.next();
System.out.println("");
} while
("y".equals(answer));
if
("n".equals(answer)) {
System.out.println("系統退出,謝謝使用!");

}

}
}

『拾』 用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);
}
}
熱點內容
櫻花伺服器測試ip 發布:2024-09-20 20:10:39 瀏覽:279
爐石傳說安卓怎麼玩 發布:2024-09-20 20:09:59 瀏覽:312
ios開會員為什麼比安卓貴 發布:2024-09-20 20:09:55 瀏覽:568
緩存伺服器redis 發布:2024-09-20 20:09:01 瀏覽:75
優酷上傳ts 發布:2024-09-20 19:55:58 瀏覽:273
minecraft怎麼開伺服器地址 發布:2024-09-20 19:52:14 瀏覽:651
android彈出布局 發布:2024-09-20 19:14:29 瀏覽:981
預演算法包括 發布:2024-09-20 18:52:07 瀏覽:764
什麼數字後面跟著密碼 發布:2024-09-20 18:52:07 瀏覽:878
訂座源碼 發布:2024-09-20 18:52:06 瀏覽:383