java 制作抽奖小程序

java 制作抽奖小程序,第1张

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

import javaappletApplet;

import javaawtButton;

import javaawtColor;

import javaawtGraphics;

import javaawtTextField;

import javaawteventActionEvent;

import javautilRandom;

import javautilVector;

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();

thissetSize(w, h);

thissetLayout(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=0;i<4;i++){

gaiLv[i]=new TextField("00"+(i+1));

thisadd(gaiLv[i]);

gaiLv[i]setBounds(mx+ml, 75+i26, 60, 18);

jiangPin[i]=new TextField();

thisadd(jiangPin[i]);

jiangPin[i]setBounds(mx+ml3, 75+i26, 80, 18);

}

thisadd(ok);

oksetBounds(260, 180, 60, 28);

okaddActionListener(new LotButtonAction(this));

thisadd(out);

outsetBounds(330, 180, 60, 28);

outaddActionListener(new LotButtonAction(this));

thisadd(setup);

setupsetBounds(110, 180, 80, 24);

setupaddActionListener(new LotButtonAction(this));

}

public void paint(Graphics g){

gsetColor(Colorwhite);

gfillRect(0, 0, thisgetWidth(), thisgetHeight());

gsetColor(new Color(230,255,230));

gfillRect(0, 0, w, 30);

gsetColor(ColorBLUE);

gdrawString("JAVA抽奖系统", 130, 20);

gsetColor(ColorORANGE);

gdrawRect(10, 40, 230, 170);

gsetColor(ColorBLACK);

gdrawString("设置", mx, 60);

gdrawString("概率", mx+ml, 60);

gdrawString("奖品", mx+ml3, 60);

for(int i=0;i<msglength;i++){

gsetColor(new Color(255-(i30),45,89));

gdrawString(msg[i], 20, 90+i26);

}

if(lot==true){

gsetColor(new Color(rannextInt(255),rannextInt(255),rannextInt(255)));

if(priseMsglength()<=7){

gdrawString(priseMsg, 260, 100);

}else{

gdrawString(priseMsgsubstring(0, 5), 260, 100);

gdrawString(priseMsgsubstring(5), 260, 120);

}

}

if(iserr==true){

gdrawString(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=FloatparseFloat(gaiLv[0]getText());

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

iserr=true;

return;

}

if(firu<minu){

minu=firu;

}

}

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

secu=FloatparseFloat(gaiLv[1]getText());

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

iserr=true;

return;

}

if(secu<minu){

minu=secu;

}

}

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

thiu=FloatparseFloat(gaiLv[2]getText());

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

iserr=true;

return;

}

if(thiu<minu){

minu=thiu;

}

}

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

fouu=FloatparseFloat(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{

fistremoveAllElements();

}

count=(int)(secu/minu);

if(secu!=1){

sec=getLotteryVec(maxNum,count);

}else{

secremoveAllElements();

}

count=(int)(thiu/minu);

if(thiu!=1){

third=getLotteryVec(maxNum,count);

}else{

thirdremoveAllElements();

}

count=(int)(fouu/minu);

if(fouu!=1){

lucky=getLotteryVec(maxNum,count);

}else{

luckyremoveAllElements();

}

issetup=true;

iserr=false;

}

protected Vector<Integer> getLotteryVec(int maxNum,int num){

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

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

resultadd(rannextInt(maxNum));

}

return result;

}

protected int getaNum(){

return rannextInt(maxNum);

}

public int isLucky(int pNum){

for(int i=0;i<fistsize();i++){

if(fistget(i)==pNum){

return 1;

}

}

for(int i=0;i<secsize();i++){

if(secget(i)==pNum){

return 2;

}

}

for(int i=0;i<thirdsize();i++){

if(thirdget(i)==pNum){

return 3;

}

}

for(int i=0;i<luckysize();i++){

if(luckyget(i)==pNum){

return 4;

}

}

return -1;

}

public void ButtonActionPerformed(ActionEvent e){

String acName=egetActionCommand();

if(acNameequals("抽奖")){

if(issetup==false){

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

lot=true;

repaint();

lot=false;

return;

}

lot=true;

priseMsg=getResult(getaNum());

repaint();

// lot=false;

}else if(acNameequals("退出")){

thissetVisible(false);

thisstop();

thisdestroy();

Systemexit(0);

}else if(acNameequals("确认设置")){

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 javaawteventActionListener{

Lottery su;

public LotButtonAction(Lottery bun){

thissu=bun;

}

@Override

public void actionPerformed(ActionEvent e) {

suButtonActionPerformed(e);

}

}

微信中有很多小程序可以扫码抽奖,以下是一些常用的:

1 微信官方提供的“摇一摇”功能:在微信首页左上角点击“发现”,然后选择“摇一摇”,即可进入该功能。通过手机晃动或者点击屏幕进行抽奖。

2 “口袋抽奖”小程序:可以自定义设置奖项和数量,并生成对应二维码供用户扫描参与抽奖。

3 “乐逗互动”小程序:支持在线制作各种类型的营销活动,包括刮刮卡、大转盘、砸金蛋等,用户可以通过扫描二维码参与活动。

4 “易赞助”小程序:主要面向公益组织和企业,在筹款过程中使用该平台进行线上募捐和抽奖等活动。

以上仅是部分示例,实际上还有很多其他类似的小程序可供选择。需要注意的是,在使用任何第三方平台前,请务必了解其相关规定及费用情况,并确保合法合规。

方法/步骤:

1首先我们打开表格,在表格里制作三个框。

2分别为:中奖名单、中奖编号和中奖人。

3在中奖编号旁边的框里,输入函数:RANDBETWEEN()。在括号里,填入参与的人数。

4在中奖人下面的框里,填入函数:VLOOKUP()。

5在括号里“选中抽奖名单——逗号——选择2(姓名)——逗号——FALSE精确匹配。然后回车

Dim n As Integer

Dim a()

Private Sub Command1_Click()

    If n = 0 Then            '第一次点击时执行

        m = Val(Text1)

        ReDim a(1 To m)

        For i = 1 To m      '生成数组a,元素为1至m这m个数

            a(i) = i

        Next

        For i = 1 To m - 1             '随机打乱数组a中元素

            r = Int(Rnd  m + 1)

            tmp = a(i)

            a(i) = a(r)

            a(r) = tmp

        Next

    End If

    n = n + 1                 '计数点击次数

    If n > Val(Text1) Then    '次数超过指定次数,抽奖结束

        MsgBox "抽奖结束!"

        Exit Sub

    End If

    Text2 = a(n)              '从数组中抽出第n个数,由于数组中是随机排列,所以相当于生成一个随机数,并且不会重复

End Sub

首先打开手机,进入微信。点击抽奖助手功能选择点击抽奖助手功能。点击发起抽奖功能选择点击发起抽奖功能。点击输入所有抽奖信息后点击发起抽奖功能,选择点击输入所有抽奖信息后点击发起抽奖功能。打开微信发现页面,点击小程序。搜索“活动抽奖”。然后点击发起抽奖。完善了奖品信息,填写抽奖说明,可以在这里描述此次抽奖的目的或者小要求,填写两个条件,必须是个人的公众号粉丝才能抽奖。高级功能的使用。

1、注册一个小程序账号,注意这里需要用一个没注册过公众号的邮箱注册。2、注册过程中需要很多认证,有很多认证,比较繁琐,如果暂时只是开发测试,不进行提审、发布的话,只要完成营业执照号填写就可以了,不需要完成微信认证。

以上就是关于java 制作抽奖小程序全部的内容,包括:java 制作抽奖小程序、微信什么小程序可以扫码抽奖的、wps中如何使用vba设计一个游戏抽奖小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10133360.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存