• Android-3


    九宫格抽奖

    package com.example.nine;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    import org.w3c.dom.Text;
    
    import java.lang.reflect.Array;
    import java.util.ArrayList;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            //引入组件
            final Button b1 = (Button)findViewById(R.id.b1);
            final Button b2 = (Button)findViewById(R.id.b2);
            final Button b3 = (Button)findViewById(R.id.b3);
            final Button b4 = (Button)findViewById(R.id.b4);
            final Button b5 = (Button)findViewById(R.id.b5);
            final Button b6 = (Button)findViewById(R.id.b6);
            final Button b7 = (Button)findViewById(R.id.b7);
            final Button b8 = (Button)findViewById(R.id.b8);
            final Button b9 = (Button)findViewById(R.id.b9);
            final TextView t1 = (TextView)findViewById(R.id.text);
            //设置监听
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //点击事件执行,同时关闭其余按钮
                    t1.setText("恭喜你中奖了!");
                    b1.setText("100元");
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setText("HUAWEI");
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setText("xiaomi");
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setText("1角");
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setText("ipad");
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setText("AKW");
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b7.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setText("M416");
                    b8.setClickable(false);
                    b9.setClickable(false);
                }
            });
            b8.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("很遗憾,你没有中奖!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setText("谢谢惠顾");
                    b9.setClickable(false);
                }
            });
            b9.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    t1.setText("恭喜你中奖了!");
                    b1.setClickable(false);
                    b2.setClickable(false);
                    b3.setClickable(false);
                    b4.setClickable(false);
                    b5.setClickable(false);
                    b6.setClickable(false);
                    b7.setClickable(false);
                    b8.setClickable(false);
                    b9.setText("笑口常开");
                }
            });
        }
    }

    代码运行截图

     Component Tree

    应用登陆界面代码

    package com.example.homework2;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RadioButton;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button blogin = (Button)findViewById(R.id.enter);//先引用组件,然后执行算法
            blogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String user = "zhangsan";
                    String password = "123456";
                    EditText u = (EditText)findViewById(R.id.etname);
                    EditText p = (EditText)findViewById(R.id.etpass);
                    if (u.getText().toString().equals(user)){//判断用户名是否正确
                        //读取文本信息,转为字符串,判断正确
                        if (p.getText().toString().equals(password)){
                    //消息提示 Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show(); }else{ //密码输入错误 Toast.makeText(MainActivity.this, "密码错误", Toast.LENGTH_LONG).show(); } }else{ //用户名错误提示 Toast.makeText(MainActivity.this, "用户名错误", Toast.LENGTH_LONG).show(); } } }); } }

    代码未实现记住密码与忘记密码选项,初始用户名为:zhangsan,初始密码为:123456.

    代码运行截图

     Component Tree 截图

  • 相关阅读:
    VC++ 调用C# dll 回调函数,实现MQTT协议客户端通信
    如何正确获取ADO连接MySql的连接字符串(转载)
    SQL 操作
    MFC如何添加背景图片(转载)
    MFC CFont 要释放的资源总结
    MFC控件 Edit,控制只能输入数字和小数点
    VC MFC 获取 IP地址和MAC地址程序
    MFC CString 转 CTime
    vc mfc 写excel文件,包括数据和图表
    ADO方式操作access数据库
  • 原文地址:https://www.cnblogs.com/yunlan/p/13624587.html
Copyright © 2020-2023  润新知