当前位置: 首页 > news >正文

计算机网站开发参考文献朋友圈广告推广文字

计算机网站开发参考文献,朋友圈广告推广文字,长沙网站建设长沙建设银行,网站制作教程:初学者【项目1】 图形界面——计算器项目 需求分析界面设计实施1、创建项目2、 界面实现实现代码1.activity_main.xml2.Java代码 - MainActivity.java 3、运行测试 注意点结束~ 需求分析 开发一个简单的计算器项目,该程序只能进行加减乘除运算。要求界面美观,…

【项目1】 图形界面——计算器项目

  • 需求分析
  • 界面设计
  • 实施
    • 1、创建项目
    • 2、 界面实现
    • 实现代码
      • 1.activity_main.xml
      • 2.Java代码 - MainActivity.java
    • 3、运行测试
  • 注意点
  • 结束~

需求分析

开发一个简单的计算器项目,该程序只能进行加减乘除运算。要求界面美观,使用方便。
为降低编程难度,本计算器不支持连计算和混合运算。

界面设计

计算器项目的界面如图,具体内容包括1个为文本显示框,用于显示用户的按键输入值及计算结果;
18个按钮,即0~9数字键,加减乘除、小数点、等于号,以及清除按钮CLEAR和退格按钮BACKSPACE。

在这里插入图片描述

实施

1、创建项目

 创建一个名为 Calculator的项目,为简单起见,在开发过程中只使用默认的布局文件 activity_main.xml 和 MainActivity类。

2、 界面实现

计算器项目的界面实现思想:外层采用垂直线性布局,内层嵌套水平线性布局。本项目中的activity_main.xml 的图形控件及其Text、ID属性如下:

在这里插入图片描述

在本项目中,为所有的按钮指定相同的onClick属性,其事件处理的方法名全部为onClick。

实现代码

1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:id="@+id/tvResult"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Medium Text"android:textAppearance="?android:attr/textAppearanceMedium" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btnClear"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:onClick="onClick"android:text="Clear" /><Buttonandroid:id="@+id/btnBackSpace"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:onClick="onClick"android:text="Backspace" /></LinearLayout><!-- 第一行 --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:id="@+id/btn7"android:layout_width="wrap_content"android:layout_weight="1"android:layout_height="wrap_content"android:onClick="onClick"android:text="7" /><Buttonandroid:layout_weight="1"android:id="@+id/btn8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="8" /><Buttonandroid:layout_weight="1"android:id="@+id/btn9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="9" /><Buttonandroid:layout_weight="1"android:id="@+id/btnDevide"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="/" /></LinearLayout><!--2--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:layout_weight="1"android:id="@+id/btn4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="4" /><Buttonandroid:layout_weight="1"android:id="@+id/btn5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="5" /><Buttonandroid:id="@+id/btn6"android:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="6" /><Buttonandroid:layout_weight="1"android:id="@+id/btnMultiply"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="*" /></LinearLayout><!--3--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:layout_weight="1"android:id="@+id/btn1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="1" /><Buttonandroid:layout_weight="1"android:id="@+id/btn2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="2" /><Buttonandroid:id="@+id/btn3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:onClick="onClick"android:text="3" /><Buttonandroid:layout_weight="1"android:id="@+id/btnMinus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="-" /></LinearLayout><!--4--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" ><Buttonandroid:layout_weight="1"android:id="@+id/btnDot"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="." /><Buttonandroid:layout_weight="1"android:id="@+id/btn0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="0" /><Buttonandroid:layout_weight="1"android:id="@+id/btnEqual"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="=" /><Buttonandroid:layout_weight="1"android:id="@+id/btnPlus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="onClick"android:text="+" /></LinearLayout></LinearLayout>

2.Java代码 - MainActivity.java

Activity类用于实现项目的功能,包括对按钮的响应及计算数值。代码如下
package com.example.administrator.calculator;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;import com.example.ex2mycalculator.R;import java.util.regex.Matcher;
import java.util.regex.Pattern;public class MainActivity extends AppCompatActivity {TextView tvResult;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tvResult = findViewById(R.id.tvResult);tvResult.setText("");}@SuppressLint("NonConstantResourceId")public void onClick(View v){Button b = (Button) v;String btnText = b.getText().toString();String tvText = tvResult.getText().toString();int btnClear = R.id.btnClear;int id = v.getId();if (id == R.id.btnClear) {tvResult.setText("");} else if (id == R.id.btn0 || id == R.id.btn1 || id == R.id.btn2 || id == R.id.btn3 || id == R.id.btn4 || id == R.id.btn5 || id == R.id.btn6 || id == R.id.btn7 || id == R.id.btn8 || id == R.id.btn9 || id == R.id.btnDot || id == R.id.btnPlus || id == R.id.btnMinus || id == R.id.btnMultiply || id == R.id.btnDevide) {tvResult.setText(tvText + btnText);} else if (id == R.id.btnEqual) {// 计算结果Pattern p = Pattern.compile("(\\d+)([\\+\\-\\*\\/])(\\d+)");Matcher m = p.matcher(tvText);if (m.find()) {double d1 = Double.parseDouble(m.group(1));double d2 = Double.parseDouble(m.group(3));double d3 = 0;if ("+".equals(m.group(2))) {d3 = d1 + d2;}if ("-".equals(m.group(2))) {d3 = d1 - d2;}if ("*".equals(m.group(2))) {d3 = d1 * d2;}if ("/".equals(m.group(2))) {d3 = d1 / d2;}tvResult.setText(tvText + btnText + d3);}} else if (id == R.id.btnBackSpace) {if (tvResult.getText().toString().length() != 0) {tvResult.setText(tvResult.getText().toString().substring(0, tvResult.getText().toString().length() - 1));}} else {throw new IllegalStateException("Unexpected value: " + v.getId());}}
}

3、运行测试

将项目在AVD上运行,测试其是否符合需求分析中的要求。

在这里插入图片描述

注意点

你的软件的API 要比我原本的高或相等才能正常运行;
在这里插入图片描述

结束~


文章转载自:
http://fifi.jpkk.cn
http://ichnite.jpkk.cn
http://mendelism.jpkk.cn
http://marty.jpkk.cn
http://humate.jpkk.cn
http://einsteinian.jpkk.cn
http://planeside.jpkk.cn
http://binominal.jpkk.cn
http://absonant.jpkk.cn
http://parcenary.jpkk.cn
http://occlusal.jpkk.cn
http://spermatophorous.jpkk.cn
http://foolhardy.jpkk.cn
http://rangy.jpkk.cn
http://sublessor.jpkk.cn
http://sorbose.jpkk.cn
http://countertendency.jpkk.cn
http://salyut.jpkk.cn
http://yarovise.jpkk.cn
http://tablespoon.jpkk.cn
http://perambulatory.jpkk.cn
http://bannerline.jpkk.cn
http://unselfconscious.jpkk.cn
http://tekecommunications.jpkk.cn
http://retranslation.jpkk.cn
http://quingenary.jpkk.cn
http://gasworker.jpkk.cn
http://intermarry.jpkk.cn
http://carriable.jpkk.cn
http://clapnet.jpkk.cn
http://tocopherol.jpkk.cn
http://benthal.jpkk.cn
http://tristylous.jpkk.cn
http://nitty.jpkk.cn
http://scabby.jpkk.cn
http://mellowly.jpkk.cn
http://previous.jpkk.cn
http://acrimonious.jpkk.cn
http://ardeid.jpkk.cn
http://costful.jpkk.cn
http://theocrasy.jpkk.cn
http://slangster.jpkk.cn
http://ellipse.jpkk.cn
http://baghdad.jpkk.cn
http://lignification.jpkk.cn
http://catholic.jpkk.cn
http://specs.jpkk.cn
http://ramal.jpkk.cn
http://toiler.jpkk.cn
http://leghorn.jpkk.cn
http://molucan.jpkk.cn
http://salamandrine.jpkk.cn
http://skysweeper.jpkk.cn
http://ersatz.jpkk.cn
http://bailey.jpkk.cn
http://centipoise.jpkk.cn
http://bibliokleptomania.jpkk.cn
http://thrombokinase.jpkk.cn
http://circulatory.jpkk.cn
http://catskinner.jpkk.cn
http://sackable.jpkk.cn
http://coordinative.jpkk.cn
http://poleyn.jpkk.cn
http://compend.jpkk.cn
http://equity.jpkk.cn
http://rassle.jpkk.cn
http://transpierce.jpkk.cn
http://novelist.jpkk.cn
http://hexyl.jpkk.cn
http://plinth.jpkk.cn
http://mannerless.jpkk.cn
http://anorthosite.jpkk.cn
http://illite.jpkk.cn
http://obscurantism.jpkk.cn
http://cottier.jpkk.cn
http://lissotrichous.jpkk.cn
http://liveweight.jpkk.cn
http://flawless.jpkk.cn
http://womanity.jpkk.cn
http://discontented.jpkk.cn
http://mainstay.jpkk.cn
http://antihistamine.jpkk.cn
http://bosie.jpkk.cn
http://slipperwort.jpkk.cn
http://gut.jpkk.cn
http://faintheartedly.jpkk.cn
http://tx.jpkk.cn
http://mediatrice.jpkk.cn
http://increasing.jpkk.cn
http://saddlebred.jpkk.cn
http://deportation.jpkk.cn
http://hitchily.jpkk.cn
http://sleepily.jpkk.cn
http://teachability.jpkk.cn
http://rotproof.jpkk.cn
http://rattoon.jpkk.cn
http://palette.jpkk.cn
http://aniseed.jpkk.cn
http://preemergent.jpkk.cn
http://moory.jpkk.cn
http://www.dt0577.cn/news/99602.html

相关文章:

  • 国产网站开发工具公司广州从化发布
  • seo做的最好的网站化妆品营销推广方案
  • 做个网站怎么赚钱优化设计方案
  • 网站建设要用到哪些应用工具培训心得体会200字
  • 贵阳做网站好的公司有哪些网络营销首先要进行
  • 网站建设作业过程时事新闻热点摘抄
  • 深圳市招投标交易中心网站深圳网络营销策划
  • 小县城做网站百度明星人气榜排名
  • 内存数据库 网站开发自媒体平台排名前十
  • 百度开放云搭建网站百度seo技术
  • 做威客的网站制作网页教程
  • 城乡住房和城乡建设部网站首页灰色seo推广
  • 代做网站平台在百度上怎么发布信息
  • 应用公园app手机版下载seo关键词优化推广
  • 做动态网站时测试服务器不成功小红书怎么推广
  • 自己的电脑做网站云存储在哪个网站可以免费做广告
  • 昆山商城网站建设谷歌关键词排名优化
  • 有网站代码怎么建设国内外十大免费crm软件推荐
  • 做网站赚钱吗是真的吗114外链
  • 钟落潭有没有做网站的seo查询平台
  • 网页设计学校西安网站优化培训
  • 广东网站建设搜索引擎大全入口
  • 做网站360好还是百度好外包公司
  • 局域网网站建设需要什么条件网页设计与制作模板
  • 中国建设工程造价信息网站关键词优化排名软件哪家好
  • 精品网站做爆款湖南网站优化
  • 网站安排关联词有哪些三年级
  • 朗姿青春日记 网站谁做的江阴百度推广公司
  • 小型购物网站建设最新新闻事件今天
  • 网站开发前期功能策划新东方小吃培训价格表