最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

一個算數(shù)小游戲的代碼

2020-08-24 18:41 作者:MogMouG  | 我要投稿

JAVA代碼

package com.mycompany.myapp2;


import android.app.*;

import android.os.*;

import android.view.*;

import android.view.View.*;

import android.widget.*;

public class MainActivity extends Activity?

{

? ??

?int max=10,min=1;

?int jiashu1 = (int) (Math.random() * (max - min) + min);?

?int jiashu2 = (int) (Math.random() * (max - min) + min);

?private TextView text = null;

?private Button btn = null;

?private EditText edit = null;

?private TextView exp = null;

? ? @Override

? ? protected void onCreate(Bundle savedInstanceState)

? ? {

? super.onCreate(savedInstanceState);

? ? ? ? setContentView(R.layout.main);

? this.exp = (TextView)super.findViewById(R.id.exp);

? this.text = (TextView)super.findViewById(R.id.text);

? this.btn = (Button)super.findViewById(R.id.btn);

? this.edit = (EditText)super.findViewById(R.id.edit);

? text.setText(jiashu1+"+"+jiashu2+"=?");

? btn.setOnClickListener(new btnClick());

? ? }

?private class btnClick implements OnClickListener

?{

? public void onClick(View v)

? {

? ?int sum2 = (jiashu1 + jiashu2);

? ?int sum1 = Integer.valueOf(edit.getText().toString());

? ?//Toast.makeText(MainActivity.this,,Toast.LENGTH_SHORT).show();

? ?if (sum2==sum1)

? ?{

? ? exp.setText("??");

? ?}

? ?else

? ?{

? ? exp.setText("??");

? ?}

? ?int max=10,min=1;

? ?jiashu1 = (int) (Math.random() * (max - min) + min);?

? ?jiashu2 = (int) (Math.random() * (max - min) + min);

? ?text.setText(jiashu1+"+"+jiashu2+"=?");

? }

?}

}

XML文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

?xmlns:android="http://schemas.android.com/apk/res/android"

?android:layout_width="match_parent"

?android:layout_height="match_parent"

?android:orientation="vertical"

?android:id="@+id/mainLinearLayout1"

?android:alpha="1">


?<LinearLayout

? android:layout_height="wrap_content"

? android:layout_width="wrap_content"

? android:orientation="horizontal">


? <TextView

? ?android:layout_height="wrap_content"

? ?android:layout_width="wrap_content"

? ?android:text="1+1=?"

? ?android:id="@+id/text"

? ?android:textSize="35sp"/>


? <TextView

? ?android:layout_height="wrap_content"

? ?android:layout_width="wrap_content"

? ?android:text=""

? ?android:textSize="35sp"

? ?android:id="@+id/exp"/>


?</LinearLayout>


?<EditText

? android:layout_height="wrap_content"

? android:layout_width="wrap_content"

? android:ems="9"

? android:id="@+id/edit"

? android:hint="輸入數(shù)字"

? android:inputType="number"

? style="@style/AppTheme"/>


?<Button

? android:layout_height="wrap_content"

? android:layout_width="wrap_content"

? android:text="提交"

? android:id="@+id/btn"/>


</LinearLayout>


代碼都是自己寫的

大佬勿噴QAQ

一個算數(shù)小游戲的代碼的評論 (共 條)

分享到微博請遵守國家法律
成武县| 巴林左旗| 南京市| 辽源市| 四川省| 阳城县| 无棣县| 湄潭县| 五常市| 龙岩市| 喀喇沁旗| 井研县| 汉中市| 鄂托克旗| 扎鲁特旗| 任丘市| 武宁县| 玉树县| 思茅市| 巨野县| 商水县| 新宾| 清镇市| 临漳县| 沈丘县| 白山市| 凤山市| 漳州市| 始兴县| 岳西县| 泽州县| 晋州市| 秦安县| 故城县| 观塘区| 进贤县| 昌图县| 分宜县| 霍城县| 韩城市| 错那县|