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+"谢谢您的支持!")
}
}
}
帮你做了一个,不知是否满意态歼呢?
import java.applet.Applet
import java.awt.Button
import java.awt.Color
import java.awt.Graphics
import java.awt.TextField
import java.awt.event.ActionEvent
import java.util.Random
import java.util.Vector
public class Lottery 祥闭腊extends Applet {
private static final long serialVersionUID = 1L
int w,h
Button ok,out,setup
String[] msg
TextField[] gaiLv
TextField[] jiangPin
int mx,ml
int maxNum
Random ran
Vector<Integer> fist
Vector<Integer> sec
Vector<Integer> third
Vector<Integer> lucky
boolean lot=false
boolean iserr=false
boolean issetup=false
String mesg="输入错误"
String priseMsg="继续努力!"
public void init(){
w=400
h=220
mx=20
ml=40
ran=new Random()
this.setSize(w, h)
this.setLayout(null)
ok=new Button("抽奖")
out=new Button("退出")
setup=new Button("确认设置")
msg=new String[4]
msg[0]="一等奖"
msg[1]="二等奖"
msg[2]="三谨滑等奖"
msg[3]="幸运奖"
gaiLv=new TextField[4]
jiangPin=new TextField[4]
for(int i=0i<4i++){
gaiLv[i]=new TextField("0.0"+(i+1))
this.add(gaiLv[i])
gaiLv[i].setBounds(mx+ml, 75+i*26, 60, 18)
jiangPin[i]=new TextField()
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(new LotButtonAction(this))
this.add(out)
out.setBounds(330, 180, 60, 28)
out.addActionListener(new LotButtonAction(this))
this.add(setup)
setup.setBounds(110, 180, 80, 24)
setup.addActionListener(new LotButtonAction(this))
}
public void paint(Graphics g){
g.setColor(Color.white)
g.fillRect(0, 0, this.getWidth(), this.getHeight())
g.setColor(new Color(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(int i=0i<msg.lengthi++){
g.setColor(new Color(255-(i*30),45,89))
g.drawString(msg[i], 20, 90+i*26)
}
if(lot==true){
g.setColor(new Color(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)
}
}
public void getLucky(){
float firu=1
float secu=1
float thiu=1
float fouu=1
float minu=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
}
float aNum=1/minu
maxNum=(int)aNum
int count=(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
}
protected Vector<Integer> getLotteryVec(int maxNum,int num){
Vector<Integer> result=new Vector<Integer>()
for(int i=0i<numi++){
result.add(ran.nextInt(maxNum))
}
return result
}
protected int getaNum(){
return ran.nextInt(maxNum)
}
public int isLucky(int pNum){
for(int i=0i<fist.size()i++){
if(fist.get(i)==pNum){
return 1
}
}
for(int i=0i<sec.size()i++){
if(sec.get(i)==pNum){
return 2
}
}
for(int i=0i<third.size()i++){
if(third.get(i)==pNum){
return 3
}
}
for(int i=0i<lucky.size()i++){
if(lucky.get(i)==pNum){
return 4
}
}
return -1
}
public void ButtonActionPerformed(ActionEvent e){
String acName=e.getActionCommand()
if(acName.equals("抽奖")){
if(issetup==false){
priseMsg="请先设置参数!"
lot=true
repaint()
lot=false
return
}
lot=true
priseMsg=getResult(getaNum())
repaint()
// lot=false
}else if(acName.equals("退出")){
this.setVisible(false)
this.stop()
this.destroy()
System.exit(0)
}else if(acName.equals("确认设置")){
lot=false
getLucky()
repaint()
}
}
public String getResult(int num){
int resu=isLucky(num)
String result=""
switch(resu){
case -1:
result="继续努力!"
break
case 1:
result="恭喜你!一等奖!\n获得"+jiangPin[0].getText()
break
case 2:
result="恭喜你!二等奖!\n获得"+jiangPin[1].getText()
break
case 3:
result="恭喜你!三等奖!\n获得"+jiangPin[2].getText()
break
case 4:
result="恭喜你!幸运奖!\n获得"+jiangPin[3].getText()
break
default:
result="继续努力!"
}
return result+num
}
}
class LotButtonAction implements java.awt.event.ActionListener{
Lottery su
public LotButtonAction(Lottery bun){
this.su=bun
}
@Override
public void actionPerformed(ActionEvent e) {
su.ButtonActionPerformed(e)
}
}
&#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)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)