您的位置:首页 > 移动开发 > 微信开发

小程序:彩票机选神器 !

2015-11-18 21:18 726 查看
package com.lixu.caipiao;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener {
Button btn1;
Button btn2;
Button btn3;
EditText et1;
EditText et2;
EditText et3;
StringBuffer sb;
StringBuffer sb2;
StringBuffer sb3;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
btn3 = (Button) findViewById(R.id.btn3);
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
et3 = (EditText) findViewById(R.id.et3);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn1:
sb = new StringBuffer();
shuang();
et1.setText(sb);
break;
case R.id.btn2:
sb2 = new StringBuffer();
daletou();
et2.setText(sb2);
break;
case R.id.btn3:
sb3 = new StringBuffer();
qixing();
et3.setText(sb3);
break;

default:
break;
}

}

public void shuang() {
int[] a = new int[7];
int i = 0;
while (i < 6) {
int b = (int) (Math.random() * 33) + 1;
boolean temp = true;
for (int m = 0; m < a.length - 1; m++) {
if (a[m] == b) {
temp = false;
}
}

if (!temp) {
continue;
}
a[i] = b;
i++;
}
for (int l = 0; l < a.length - 1; l++) {
for (int h = 0; h < a.length - 1; h++) {
if (a[l] < a[h]) {
int temp = a[l];
a[l] = a[h];
a[h] = temp;
}
}
}
int k = (int) (Math.random() * 16) + 1;
a[6] = k;
for (int n : a) {
sb.append(n + ",");
}
}

public void daletou() {
int[] a = new int[7];
int i = 0;
while (i < 5) {
int b = (int) (Math.random() * 35) + 1;
boolean temp = true;
for (int e = 0; e < a.length - 2; e++) {
if (a[e] == b) {
temp = false;
}
}
if (!temp) {
continue;
}
a[i] = b;
i++;
}
for (int m = 0; m < a.length - 2; m++) {
for (int n = m + 1; n < a.length - 2; n++) {
if (a[m] > a
) {
int temp1 = a[m];
a[m] = a
;
a
= temp1;
}
}
}
while (i > 4 && i < 7) {
int k = (int) (Math.random() * 12) + 1;
boolean temp2 = true;
for (int e = 5; e < 7; e++) {
if (a[e] == k) {
temp2 = false;
}
}
if (!temp2) {
continue;
}
a[i] = k;
i++;
}
for (int m = 5; m < 7; m++) {
for (int n = m + 1; n < 7; n++) {
if (a[m] > a
) {
int temp1 = a[m];
a[m] = a
;
a
= temp1;
}
}
}
for (int n : a) {
sb2.append(n + ",");
}
}

public void qixing() {
int[] a = new int[7];
for (int j = 0; j < 7; j++) {
int b = (int) (Math.random() * 10);
a[j] = b;
}
for (int n : a) {
sb3.append(n + ",");
}

}
}


xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.lixu.caipiao.MainActivity" >

<EditText
android:id="@+id/et1"
android:layout_width="210dp"
android:layout_height="50dp"
android:hint="等待输入"
android:background="@drawable/round"/>

<EditText
android:id="@+id/et2"
android:layout_width="210dp"
android:layout_height="50dp"
android:layout_below="@id/et1"
android:hint="等待输入"
android:background="@drawable/round"
/>

<EditText
android:id="@+id/et3"
android:layout_width="210dp"
android:layout_height="50dp"
android:layout_below="@id/et2"
android:hint="等待输入"
android:background="@drawable/round"/>

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="双色球机选"
android:background="@drawable/round"/>

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/et2"
android:layout_alignBottom="@+id/et2"
android:layout_alignParentRight="true"
android:text="大乐透机选"
android:background="@drawable/round"/>

<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/btn2"
android:text="七星彩机选"
android:background="@drawable/round"/>
</RelativeLayout>


运行效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: