java抽奖软件源码(抽奖源码下载)
本文目录一览:
- 1、java抽奖小程序源码
- 2、用java写一个抽奖程序
- 3、java抽奖程序
- 4、我用java准备写一个抽奖软件,刚学java,一个Button开始按钮,一个Lable显示文本组件
- 5、用swing编写一个java抽奖的程序,至少有5个按钮,显得高大上一点。
java抽奖小程序源码
import java.util.Scanner;
public class ChouJiang {
public static void main(String[] args) {
System.out.println("我行我素购物管理系统幸运抽奖");
System.out.println("");
System.out.println("");
Scanner input=new Scanner(System.in);
System.out.print("请输入四位会员号:");
int hyh=input.nextInt();
int q,b,s,g,sum;
q=hyh/1000;
b=hyh/100%10;
s=hyh/10%10;
g=hyh%10;
sum=q+b+s+g;
if(sum=23)
{
System.out.println(hyh+"是幸运客户,获精美MP3一台!");
}else
{
System.out.println(hyh+"谢谢您的支持!");
}
}
}
用java写一个抽奖程序
你是要JAVA可视化的 还是控制台的啊?
控制台的话 你可以用循环来取中奖号,将其存入list或set里(最好是set,因为set本来就不会重复)。如果用list存就另外写一个循环方法,来挨个判定该元素是不是已经在list中存在了,如果存在,就让选号的再加选一次,如果不重复,就放到list里去。。。。OK
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 bai=custNo/100%10;
while(i==1){
if(custNo=1000custNo=9999){
break;
}
else{
System.out.println("\n会员号码输入有误,请重新输入:");
custNo=input.nextInt();
continue;
}
}
if(bai==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准备写一个抽奖软件,刚学java,一个Button开始按钮,一个Lable显示文本组件
IO,Input和Output,输入和输出;一般针对文件读写、网络数据流等等;
抽奖,如果按人名随机抽奖,人不多的话,你不嫌麻烦,可以用List,程序初始化时,将人名一个一个添加到List中,然后点击按钮,启动线程并搭配“随机数(=0list的size)”和delay时间间隔来控制label上的文字显示;再点击按钮,线程停止,label上显示的则是中奖的人名。
如果将所有人名写到某个文件中,例如txt,在程序初始化话时候,先将txt文件中的数据按相应的格式全部读取到List或者数组中,然后 后面的逻辑和上面一样。
程序没有输出,也不太需要,只是可能采用输入流的方式来读取文件中的人名,最后Label显示的中奖人名也不算是输出,只是改变了文本框里的东西。
用swing编写一个java抽奖的程序,至少有5个按钮,显得高大上一点。
#8205;
import java.awt.Color;//界面不是很高大上档次,但是能满足你的基本需求,希望对你有用
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
public class 抽奖游戏 extends JFrame {
static 抽奖游戏 frame;
public 抽奖游戏() {
setLayout(new GridLayout(3, 3, 3, 3));
Border border = new LineBorder(Color.BLUE, 4);
JButton l1 = new JButton();
JButton l2 = new JButton();
JButton l3 = new JButton();
JButton l4 = new JButton();
JButton l5 = new JButton();
JButton l6 = new JButton();
JButton l7 = new JButton("祝你好运");
JButton l8 = new JButton("中奖规则");
JButton l9 = new JButton("再次抽奖");
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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "游戏规则:\n" + "特等奖:\n"
+ "第一行或者第二行出现的数字全部相同\n"
+ "第一第二行出现升序的1,2,3,4,5,6或者降序的6,5,4,3,2,1\n" + "一等奖\n"
+ "1:第一行或第二行的数字降序排列或者升序排列\n"
+ "2:第一行或者第二行相邻的按钮出现一样的数字\n");
}
});
l9.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
l1.setText("*");
l2.setText("*");
l3.setText("*");
l4.setText("*");
l5.setText("*");
l6.setText("*");
l7.setBackground(Color.lightGray);
l7.setText("离中奖不远了!");
}
});
l6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Math.random() * 10) % 6;
l1.setText(num2[j1]);
int j2 = (int) (Math.random() * 10) % 6;
l2.setText(num2[j2]);
int j3 = (int) (Math.random() * 10) % 6;
l3.setText(num2[j3]);
int j4 = (int) (Math.random() * 10) % 6;
l4.setText(num2[j4]);
int j5 = (int) (Math.random() * 10) % 6;
l5.setText(num2[j5]);
int j6 = (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("特等奖");
} else if (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("未中奖,加油!");
}
}
});
Font font = new Font("", 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);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame = new 抽奖游戏();
frame.setTitle("抽奖大战");
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}