基于安卓的计算器的设计与实现

合集下载

基于Android的计算器

基于Android的计算器

基于Android的计算器引言计算器是人们日常生活中常用的工具之一。

随着智能手机的广泛应用,计算器应用也成为了手机中的一个必备工具。

本文将介绍基于Android平台开发的计算器应用。

功能特点1.基本四则运算:加减乘除2.小数点输入和计算3.括号嵌套运算4.撤销和重做操作5.运算结果精确显示技术实现开发环境•Android Studio:用于开发Android应用的集成开发环境•Java语言:用于编写Android应用程序的主要语言用户界面设计计算器应用的用户界面需要具备简洁、直观的特点,方便用户进行操作。

基于Android平台的计算器通常使用网格布局来展示数字和功能按钮。

每个按钮都会响应用户的点击事件。

数据处理计算器应用的核心功能是进行数学运算。

因此,需要通过算法来处理用户输入的数学表达式。

一般情况下,可以使用栈数据结构来解决这个问题。

通过将中缀表达式转换为后缀表达式,然后再通过后缀表达式进行计算,即可得到最终的结果。

界面交互计算器应用需要监听用户的输入操作,并根据用户的操作更新界面。

例如,当用户点击了数字按钮或者符号按钮时,计算器应该能够正确地处理用户的输入,并实时更新显示的表达式和结果。

数据精确性为了保证计算结果的精确性,可以使用BigDecimal类来进行数值运算。

BigDecimal类可以处理浮点数运算时的精度问题,并提供了大数运算的功能。

开发过程创建Android计算器项目首先在Android Studio中创建一个新的Android项目。

选择适当的项目名称、包名和最低支持的Android版本。

设计用户界面布局使用XML布局文件来设计计算器应用的用户界面。

使用网格布局来创建数字和操作按钮,并设置按钮的点击事件监听。

添加按钮点击事件在Java代码中,为计算器界面上的按钮添加点击事件监听器。

根据用户的点击事件,对用户输入的数学表达式进行处理,并更新界面的显示。

数学表达式处理通过算法处理用户输入的表达式。

Android平台上的计算器设计

Android平台上的计算器设计

武汉工程大学计算机科学与工程学院综合设计报告设计名称:信息系统综合设计设计题目:Android平台上的计算器设计学生学号:专业班级:学生姓名:学生成绩:指导教师(职称):吴静(讲师)课题工作时间:2012年3月19日至2012年5月25日说明:1、报告中的第一、二、三项由指导教师在综合设计开始前填写并发给每个学生;四、五两项(中英文摘要)由学生在完成综合设计后填写。

2、学生成绩由指导教师根据学生的设计情况给出各项分值及总评成绩。

3、指导教师评语一栏由指导教师就学生在整个设计期间的平时表现、设计完成情况、报告的质量及答辩情况,给出客观、全面的评价。

4、所有学生必须参加综合设计的答辩环节,凡不参加答辩者,其成绩一律按不及格处理。

答辩小组成员应由2人及以上教师组成。

5、报告正文字数一般应不少于5000字,也可由指导教师根据本门综合设计的情况另行规定。

6、平时表现成绩低于6分的学生,其综合设计成绩按不及格处理。

7、此表格式为武汉工程大学计算机科学与工程学院提供的基本格式(适用于学院各类综合设计),各教研室可根据本门综合设计的特点及内容做适当的调整,并上报学院批准。

成绩评定表学生姓名:学号:班级:答辩记录表指导教师评语目录摘要........................................................................................................................................................ - 1 -ABSTRACT ............................................................................................................................................... - 2 -第一章引言.............................................................................................................................................. - 3 -1.1课题背景及意义 (3)1.1.1课题背景................................................................................................................................ - 3 -1.1.2课题相关的技术知识.............................................................................................................. - 4 -1.2智能手机平台系统 (7)1.3课题来源 (8)第二章系统分析...................................................................................................................................... - 9 -2.1系统可行性分析 (9)2.2系统的开发语言的选择 (9)2.3系统的开发工具简介 (9)2.3.1 JDK .......................................................................................................................................... - 9 -2.3.2 WTK ....................................................................................................................................... - 10 -2.3.3 Eclipse .................................................................................................................................... - 10 -2.3.4 EclipseMe ................................................................................................................................- 11 -第三章基于ANDROID平台计算器相关技术概述............................................................................ - 12 -3.1A NDROID手机平台 (12)3.1.1Android起源及优势 .............................................................................................................. - 12 -3.1.2Android体系结构 .................................................................................................................. - 12 -3.1.3Android平台功能特征 .......................................................................................................... - 14 -3.2A NDROID SDK介绍 (15)3.3XML技术 (16)3.4JNI技术 (16)第四章基于ANDROID平台计算器设计............................................................................................ - 18 -4.1系统的总体设计 (18)4.2程序流程和系统功能设计 (18)4.2.1 程序流程设计....................................................................................................................... - 18 -4.2.2 系统功能设计....................................................................................................................... - 19 -4.3基于A NDROID平台系统具体设计 (20)4.3.1 总体模块详细设计............................................................................................................... - 20 -4.3.2 输入模块详细设计............................................................................................................... - 20 -4.3.3 显示模块详细设计............................................................................................................... - 21 -4.3.4 计算模块详细设计............................................................................................................... - 21 -第五章计算器系统实现........................................................................................................................ - 23 -5.1A NDROID应用程序构成 (23)5.2A NDROID应用系统文件结构 (23)5.3构建A NDROID应用程序用户界面 (25)5.3.1 Android应用程序界面组件.................................................................................................. - 25 -5.3.2 Android应用系统界面组件.................................................................................................. - 26 -5.3.3 Android用户界面的实现...................................................................................................... - 27 -5.4计算模块的实现 (30)武汉工程大学计算机科学与工程学院综合设计报告5.5计算器演示 (33)总结...................................................................................................................................................... - 35 -致谢...................................................................................................................................................... - 36 -参考文献.................................................................................................................................................. - 37 -附录.......................................................................................................................................................... - 38 -摘要目前手机可以说是普及率非常高的电子设备了,由于其便于携带,使用方便,资费适中等等原因,现在手机已经在一定程度开始代替固定电话的通话功能,以及一些原来电脑软件上的功能了。

基于Android计算器功能的实现毕业设计

基于Android计算器功能的实现毕业设计

基于Android计算器功能的实现摘要随着移动通信技术和网络技术的迅速发展,手机系统发生了巨大的变化,从进行简单通话功能的非智能手机到现在集上网、聊天、收发邮件、视屏电话会议等各种服务于娱乐为一身的智能手机系统。

由Google公司牵头众多实力雄厚的软硬件厂商加盟成立了OMS联盟,并推出的Android平台手机系统。

作为时代的新生儿,Android手机操作平台有着得天独厚的优势广阔的发展前景。

本文正是基于Android平台开发的计算器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 设计并实现基于Android的计算器。

论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,其次对计算器系统和程序进行了分析和设计,再次对计算器进行了系统的实现,并对系统进行了严格的验证,最后本文对所做工作进行了总结。

关键词:手机,Android,用户界面,计算器THE CALCULATOR FUNCTION REALIZATION BASEDON ANDROIDABSTRACTWith the development of mobile communication technology and network technology, great changes have taken place on the mobile phone system. The original mobile phone only has the functions of communication and Smartphone has the functions of internet, chat, video conferencing and other services and entertainment. Android mobile phone platform which was developed by Google Company and many equipment manufacturers of hardware and software vendors, as the era of neonatal has a unique advantage and prospects for development. This article is based on the Android platform calculator. The thesis describes object-oriented programming language eclipse development tools, design and implement a calculator based on the Android. The paper first introduces the Android development platform and environment as well as an important part of the Android project, followed by the calculator systems and procedures analysis and design, the realization of the system once again the calculator, and strict verification, Finally, a summary of the work done.Key words: mobile phone, Android, UI, calculator毕业设计(论文)原创性声明和使用授权说明原创性声明本人郑重承诺:所呈交的毕业设计(论文),是我个人在指导教师的指导下进行的研究工作及取得的成果。

基于Android平台的绩点计算器设计与实现

基于Android平台的绩点计算器设计与实现
一、Android概述
1.1 Android简介
Android这一词原本的意思是指“机器人”,Google公司在2008年宣布一款基于Linux平台的开源手机操作系统,这款操作系统的名字也叫Android,它是第一个为移动终端打造的真正开放、完整的移动软件,它的开放性是非常高的。[5]操作系统、中间件、用户界面和应用软件构成该操作平台。[6]现如今大多数智能手机的系统都是Android系统,而现在智能手机已经渐渐融入我们的生活的方方面面,我们越来越离不开手机,一些手机应用深入人心,因此,安卓系统已经广为人知。
二、绩点制概念及计算方法
由于学分制只能计算学习的量,导致学生只追求修满学分,而不注重学习成绩的质量,学生之间的成绩也不能进行横向比较。绩点是计算学习成绩的一种方法。[8]平均学分绩点(General Point Average,即GPA)是以学分与绩点作为衡量学生学习的量与质的计算单位,以取得一定的学分和平均学分绩点作为毕业以及获得学位的标准,实施多样化的教育规格以及较为灵活的教学管理制度。[9]绩点体现了课程学习的质量好,将该学生掌握课程知识的情况得以反映,而不包含绩点的学分制是不够完善的。[10]相应的课程成绩对应着相应的课程绩点,计算学分绩点,要将某个学生所修的全部课程(重修的课程也要包含在内)的课程成绩对应的课程绩点乘以该门课程的学分,计算学分总计,则将学分绩点累加后再除以总的课程学分。
【 关 键 词 】学分;绩点制;Android;eclipse
目录
引言 3
一、 Android概述 4
1.1 Android简介 4
1.2 Android现状 4
二、绩点制概念及计算方法 4
三、研究内容及意义 5
四、系统分析 5
五、系统设计 5

android开发——简易计算器的设计报告

android开发——简易计算器的设计报告

简易计算机的设计摘要:Android是当今最重要的手机开发平台之一,它是建立在Java基础之上的,能够迅速建立手机软件的解决方案。

Android的功能十分强大,成为当今软件行业的一股新兴力量。

Android基于Linux平台,由操作系统、中间件、用户界面和应用软件组成,具有以下5个特点:开放性、应用程序无界限、应用程序是在平等条件下创建的、应用程序可以轻松的嵌入网络、应用程序可以并行运行。

一、实训目的1、了解Android系统,学会Android开发环境的搭建。

2、了解E clipse,学会用E clipse和Java 开发一个Android程序。

3、进一步巩固课堂上所学到的知识,深刻把握Java语言的重要概念及其面向对象的特性,能够熟练的应用面向对象的思想和设计方法解决实际问题的能力。

4、巩固所学Java语言基本知识,增进Java语言编辑基本功,掌握JDK、Editplus、Eclipse、JCreator等开发工具的运用,拓宽常用类库的应用。

二、实训任务1、Activity的相关知识简单理解Activity 代表一个用户所能看到的屏幕,Activity 主要是处理一个应用的整体性工作。

Activity是最基本的Android 应用程序组件,应用程序中,一个活动通常就是一个单独的屏幕。

每一个活动都被实现为一个独立的类,并且从活动基类中继承而来,活动类将会显示由视图控件组成的用户接口,并对事件做出响应。

大多数的应用是由多个屏幕显示组成,因而要用到多个Activity。

(1)Activity的相关方法及相关函数:void onCreate(Bundle)首次启动时调用,接受参数:Null or savedInstanceState(保存的以前某些状态信息);void onStart() 说明了将要显示给用户的活动;void onRestart()将处于停止状态的活动重新显示给用户;void onResume()用户可以开始与活动进行交互时调用。

《Android编程技术》---基于Android的简易的计算器的设计与实现

《Android编程技术》---基于Android的简易的计算器的设计与实现
clear_flag=false;
etinput="";
etInput.setText("");
}
etInput.setText(etinput+((Button)v).getText());//点击数字和小数点直接显示内容
break;
caseR.id.btJia:
caseR.id.btJian:
caseR.id.btMul:
btMul.setOnClickListener(this);
btDivide.setOnClickListener(this);
btEqu.setOnClickListener(this);
btClear.setOnClickListener(this);
btDel.setOnClickListener(this);
cleБайду номын сангаасr_flag=false;
return;
}
clear_flag=true;
doubleresult=0;
String s1=exp.substring(0,exp.indexOf(" "));//运算符前面的字符串
String op=exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2);//运算符,是根据运算符前边的空格计算的
privateButtonbtJian;
privateButtonbtMul;
privateButtonbtDivide;
privateButtonbtEqu;
privateButtonbtClear;

android简易计算器的实现

android简易计算器的实现

android简易计算器的实现最近接触了android开发就试着写了⼀个计算器的⼩程序:在xml⽂件中的布局代码如下:1<?xml version="1.0" encoding="utf-8"?>2<LinearLayout xmlns:android="/apk/res/android"3 xmlns:tools="/tools"4 android:id="@+id/activity_ji_suan02"5 android:layout_width="match_parent"6 android:layout_height="match_parent"7 android:orientation="vertical"8 tools:context="com.example.whs.sample01_1_activity.JiSuanActivity02">910<TextView11android:id="@+id/tv"12 android:layout_width="match_parent"13 android:layout_height="40dp"14 android:textSize="30dp"15 android:text="0"16 android:textColor="#ff0000"17 android:gravity="center_vertical|right"18 android:layout_marginRight="5dp"19 android:layout_marginLeft="5dp"20 android:background="#FFFF00"21/>22<!--7 8 9 + -->23<LinearLayout24android:layout_width="match_parent"25 android:layout_height="wrap_content"26 android:paddingTop="5dp"27 android:orientation="horizontal"28>2930<Button31android:id="@+id/Button07"32 android:text="7"33 android:textSize="25dp"34 android:layout_width="80dp"35 android:layout_height="wrap_content"/>36<Button37android:id="@+id/Button08"38 android:text="8"39 android:textSize="25dp"40 android:layout_width="80dp"41 android:layout_height="wrap_content"/>42<Button43android:id="@+id/Button09"44 android:text="9"45 android:textSize="25dp"46 android:layout_width="80dp"47 android:layout_height="wrap_content"/> 48<Button49android:id="@+id/ButtonJia"50 android:text="+"51 android:textSize="25dp"52 android:layout_width="80dp"53 android:layout_height="wrap_content"/> 5455</LinearLayout>5657<!--4 5 6 - -->58<LinearLayout59android:layout_width="match_parent"60 android:layout_height="wrap_content"61 android:paddingTop="5dp"62 android:orientation="horizontal"63>6465<Button66android:id="@+id/Button04"67 android:text="4"68 android:textSize="25dp"69 android:layout_width="80dp"70 android:layout_height="wrap_content"/> 71<Button72android:id="@+id/Button05"73 android:text="5"74 android:textSize="25dp"75 android:layout_width="80dp"76 android:layout_height="wrap_content"/> 77<Button78android:id="@+id/Button06"79 android:text="6"80 android:textSize="25dp"81 android:layout_width="80dp"82 android:layout_height="wrap_content"/> 83<Button84android:id="@+id/ButtonJian"85 android:text="-"86 android:textSize="25dp"87 android:layout_width="80dp"88 android:layout_height="wrap_content"/> 8990</LinearLayout>9192<!--1 2 3 * -->93<LinearLayout94android:layout_width="match_parent"95 android:layout_height="wrap_content"96 android:paddingTop="5dp"97 android:orientation="horizontal"98>99100<Button101android:id="@+id/Button01"102 android:text="1"103 android:textSize="25dp"104 android:layout_width="80dp"105 android:layout_height="wrap_content"/> 106<Button107android:id="@+id/Button02"108 android:text="2"109 android:textSize="25dp"110 android:layout_width="80dp"111 android:layout_height="wrap_content"/> 112<Button113android:id="@+id/Button03"114 android:text="3"115 android:textSize="25dp"116 android:layout_width="80dp"117 android:layout_height="wrap_content"/> 118<Button119android:id="@+id/ButtonCheng"120 android:text="*"121 android:textSize="25dp"122 android:layout_width="80dp"123 android:layout_height="wrap_content"/> 124125</LinearLayout>126127<!--0 C = / -->128<LinearLayout129android:layout_width="match_parent"130 android:layout_height="wrap_content"131 android:paddingTop="5dp"132 android:orientation="horizontal"133>134135<Button136android:id="@+id/Button00"137 android:text="0"138 android:textSize="25dp"139 android:layout_width="80dp"140 android:layout_height="wrap_content"/>141<Button142android:id="@+id/ButtonC"143 android:text="C"144 android:textSize="25dp"145 android:layout_width="80dp"146 android:layout_height="wrap_content"/>147<Button148android:id="@+id/ButtonDeng"149 android:text="="150 android:textSize="25dp"151 android:layout_width="80dp"152 android:layout_height="wrap_content"/>153<Button154android:id="@+id/ButtonChu"155 android:text="/"156 android:textSize="25dp"157 android:layout_width="80dp"158 android:layout_height="wrap_content"/>159160</LinearLayout>161162163164165166</LinearLayout>在activity中实现具体的功能1package com.example.whs.sample01_1_activity;23import android.provider.Settings;4import android.support.v7.app.AppCompatActivity;5import android.os.Bundle;6import android.view.View;7import android.widget.Button;8import android.widget.TextView;9import android.widget.Toast;1011public class JiSuanActivity02 extends AppCompatActivity {1213 TextView tv;14int[] buttons; //数字按钮数组15int result;16int result0;17int result1;1819//按钮对象声明20 Button buttonC;21 Button buttonJia;22 Button buttonJian;23 Button buttonCheng;24 Button buttonChu;25 Button buttonDengyu;2627 String str1; //旧输⼊的值28 String str2; //新输⼊的值2930int flag=0; //计算标志位,0第⼀次输⼊;1加; 2减; 3乘; 4除; 5等于 31 Button temp;3233 @Override34protected void onCreate(Bundle savedInstanceState) {35super.onCreate(savedInstanceState);36 setContentView(yout.activity_ji_suan02);3738 initButton();39//清空按钮点击事件40 buttonC.setOnClickListener(new View.OnClickListener() {41 @Override42public void onClick(View view) {43 str1 = "";44 str2 = "";45 tv.setText("0");46 result = 0;47 result1 = 0;48 result0 = 0;49 flag = 0;50 }51 });5253//监听54for (int i = 0; i < buttons.length; i++){55 temp = getBtnForId(buttons[i]);56 temp.setOnClickListener(new View.OnClickListener() {57 @Override58public void onClick(View view) {59if (flag != 0){60 str1 = "";61 }else {62 str1 = tv.getText().toString().trim();63if (str1.equals("0")){64 str1 = "";65 }66 }6768 str1 = str1 + String.valueOf(((Button)view).getText()); //获取新值69 tv.setText(str1);70 }71 });72 }7374 buttonListener(buttonJia, 1);75 buttonListener(buttonJian, 2);76 buttonListener(buttonCheng, 3);77 buttonListener(buttonChu, 4);7879 buttonDengyu.setOnClickListener(new View.OnClickListener() {80 @Override81public void onClick(View view) {8283 result1 = Integer.parseInt(str1);8485if (flag == 1){86 result = result0 + result1;87 }else if (flag == 2){88 result = result0 - result1;89 }else if (flag == 3){90 result = result0 * result1;91 }else if (flag == 4){92if (result1 == 0){93 Toast.makeText(JiSuanActivity02.this, "除数不能为0", Toast.LENGTH_SHORT).show();94 }else {95 result = result0 / result1;96 }9798 }else if (flag == 0){99 result = result1;100 }101 String str = (result + "").trim();102103if (result1 == 0 && flag == 4){104 str = "错误";105 }106 tv.setText(str);107 Toast.makeText(JiSuanActivity02.this, "结果是:" + result, Toast.LENGTH_SHORT).show(); 108 }109 });110 }111112//初始化控件资源113public void initButton(){114 tv = (TextView)this.findViewById();115 str1 = String.valueOf(tv.getText());116 str2 = "";117 buttonC = getBtnForId(R.id.ButtonC);118 buttonJia = getBtnForId(R.id.ButtonJia);119 buttonJian = getBtnForId(R.id.ButtonJian);120 buttonCheng = getBtnForId(R.id.ButtonCheng);121 buttonChu = getBtnForId(R.id.ButtonChu);122 buttonDengyu = getBtnForId(R.id.ButtonDeng);123124 buttons = new int[]{125 R.id.Button00,R.id.Button01,R.id.Button02,126 R.id.Button03,127 R.id.Button04,R.id.Button05,R.id.Button06,128 R.id.Button07,R.id.Button08,R.id.Button09129 };130 }131//根据id获取Button132public Button getBtnForId(int rID){133 Button btn = (Button)this.findViewById(rID);134return btn;135 }136//按钮监听137public void buttonListener(Button button, final int id){138 button.setOnClickListener(new View.OnClickListener() { 139 @Override140public void onClick(View view) {141 String str = tv.getText().toString().trim();142 result0 = Integer.parseInt(str);143//tv.setText("");144 flag = id;145 }146 });147 }148 }。

安卓计算器设计报告

安卓计算器设计报告

数学与信息技术学院嵌入式系统课程设计报告设计题目:数字计算器的设计与实现班级:学号:姓名:指导教师:完成日期:成绩:目录1 绪论 (1)1.2 研究的范围及达到的技术要求 (1)1.3 解决的主要问题 (1)1.4 设计的指导思想 (1)2 需求分析 (2)2.1 设计需求分析 (2)2.2 系统目标 (2)2.3 主体功能 (2)2.4 开发环境 (2)3 总体设计 (3)3.1 程序流程和系统功能设计 (3)3.1.1 程序流程设计 (3)3.3 程序设计的基本思路 (4)3.3.2 总体布局 (5)3.3.3 按钮事件处理 (6)4 详细设计 (6)4.1 输入模块详细设计 (6)4.2 显示模块详细设计 (7)4.3 计算模块详细设计 (7)5 编码 (8)5.1 用户界面代码设计 (8)5.1.1 activity_main.xml布局文件 (8)5.1.2 MainActivity.java主要功能文件 (9)6 结论 (12)6.1 实现的功能 (12)6.2 主要的问题 (12)数字计算器的设计与实验1 绪论1.1 设计的目的及意义(1)本课程设计的目的是通过开发一个数字计算机器,了解嵌入式产品开发的主要步骤,包括需求分析、系统结构设计、图形界面设计、驱动设计、功能优化、系统测试等,培养独立完成比较复杂的实际设计的能力。

(2)本课程设计主要是实现Android计算器,用于Android系统的用户的使用,本计算器可以实现加、减、乘、除、开方、平方等运算功能,方便了用户对于一些简单数据的计算,节省了用户的时间。

1.2 研究的范围及达到的技术要求本课程设计主要研究计算器的实现方法,应达到计算器界面友好,方便使用,具有基本的加、减、乘、除功能,支持小数运算,具有退格功能,能够删除最后一个输入,具有清除功能,即“C”。

1.3解决的主要问题随着信息时代的步伐加快,日常生活的开支、大额数字、多倍小数等的计算都需要计算器的帮助,处理数字的开方、平方同样也离不开计算器。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

安卓应用程序设计——简易计算器的实现院(系)名称专业名称学生姓名学生学号课程名称2016年6月日1.系统需求分析Android是以Linux为核心的手机操作平台,作为一款开放式的操作系统,随着Android 的快速发展,如今已允许开发者使用多种编程语言来开发Android应用程序,而不再是以前只能使用Java开发Android应用程序的单一局面,因而受到众多开发者的欢迎,成为真正意义上的开放式操作系统。

计算器通过算法实行简单的数学计算从而提高了数学计算的效率,实现计算器的界面优化,使界面更加友好,操作更加方便。

基于android的计算器的设计,系统具有良好的界面;必要的交互信息;简约美观的效果。

使用人员能快捷简单地进行操作,即可单机按钮进行操作,即时准确地获得需要的计算的结果,充分降低了数字计算的难度和节约了时间。

2.系统概要设计2.1计算器功能概要设计根据需求,符合用户的实际要求,系统应实现以下功能:计算器界面友好,方便使用,,具有基本的加、减、乘、除功能,能够判断用户输入运算数是否正确,支持小数运算,具有清除功能。

图2.1系统功能图整个程序基于Android技术开发,除总体模块外主要分为输入模块、显示模块以及计算模块这三大部分。

在整个系统中总体模块控制系统的生命周期,输入模块部分负责读取用户输入的数据,显示模块部分负责显示用户之前输入的数据以及显示最终的计算结果,计算模块部分负责进行数据的运算以及一些其他的功能。

具体的说,总体模块的作用主要是生成应用程序的主类,控制应用程序的生命周期。

输入模块主要描述了计算器键盘以及键盘的监听即主要负责读取用户的键盘输入以及响应触屏的按键,需要监听手机动作以及用指针事件处理方法处理触屏的单击动作。

同时提供了较为直观的键盘图形用户界面。

显示模块描述了计算器的显示区,即该区域用于显示用户输入的数据以及最终的计算结果,同时负责显示一些其他的信息。

计算模块则主要描述了计算器的整体,实现了计算器的界面,负责计算用户输入数据,包括加、减、乘、除等各种功能,记忆数据的相关功能,清零的功能。

图2.2三大模块2.2 输入模块设计系统如果想完成计算器中各种功能,首先用户要能进行数据输入,由于是在触屏手机上开发计算器程序,所以要求输入可以直接使用触屏进行,所以在设计的时候就要充分的考虑这一点。

正是由于考虑到这个特殊的地方,所以在进行模块设计中,选择编写输入模块类的时候会特意选取使用可以支持触屏输入的特殊增强型图形用户界面类。

输入模块主要的任务是描述计算器键盘以及实现键盘的监听,即当用户点击按键或者屏幕的时候监听会去调用相应的处理办法,本模块还需要为系统提供一个较为直观的键盘图形用户界面。

输入模块的功能图如图图2.3输入模块2.3显示模块设计作为手机计算器系统,显示部分也是必不可少的一部分。

没有显示部分就没有办法显示用户输入的数字是否正确,甚至不能显示计算出的结果,由此可见显示模块即包括输入的部分(因个人技术原因不能显示表达式的形式)也包括输出的部分。

显示模块主要完成的任务是描述计算器的显示区,该区域用于显示用户输入的数据以及最终的计算结果和一些其他信息。

同时本模块还将提供调用和设置显示的具体方法总体系统显示模块 计算模块 输入模块图2.4显示模块2.4计算模块设计系统要完成整个的计算器的功能,那么计算模块就是整个系统的重要模块。

没有计算模块系统就不能顺利的完成计算,就无法达到用户的要求。

所以计算模块的设计也是本次系统设计的重点。

系统想要能在屏幕上显示出计算器的样子要有整体的布局。

在本模块中要完成布局的具体设计,使用户能够看到整个计算器的界面。

同时系统想完成计算功能必须要处理用户的输入,当输入模块的监听传到计算模块中时,计算模块就要根据相应的方法进行进一步的处理。

图2.5计算模块3.设计与实现部分3.1应用程序构成Android应用程序一般是由Activity、Serviece、Content Provider、Intent、Intent Receiver、Notification六个组件构成。

但并非每一个Android应用程序都包含这六个组件。

(1)Activity(活动):应用程序的表示层。

Activity是Android的基本组件。

每一个activity 代表一个单独的屏幕。

每一个activity都是继承于Activity的独立类。

这个activity类将会显示出几个Views控件组成的用户接口,并对事件作出响应。

Android使用了Intent,实现在屏幕与屏幕之间跳转。

Activity跳转时只需要调用startActivity(Intent myIntent)方法。

然后,系统会在所有安装的应用程序中定义的IntentFilter中查找,找到最匹配myIntent的Intent 对应的activity。

新的activity接收到myIntent的通知后,开始启动运行。

当startActivity方法被调用将触发解析myIntent的动作,这个机制提供了两个关键的好处:能够重复利用从其他组件中以Intent的形式产生的一个请求和可以在任何时候被一个具有相同IntentFilter 的新的startActivity取代。

(2)Service(服务):Android应用程序的后台运行组件。

Service没有用户界面的程序。

服务组件在后台运行,它们可以更新数据源和可见的Activity,并触发Notification。

它们被用来执行一些需要在后台持续的常规处理。

例如媒体播放器这个activity会使用Context.startService()方法,连接到一个service上(如果这个service还没有运行将启动它)。

当连接到一个service之后,我们还可以通过service提供的接口与它进行通讯。

(3)Content Provider(内容提供器):用来管理和分享应用程序数据库。

Content Provider 是在应用程序之间共享数据的首选方法。

通过配置Content Provider允许其他应用程序访问存储的数据,也可以使用其他应用程序提供的Content Provider来访问它们存储的数据。

Android平台也提供了系统自带的Content Provider,如联系人信息等。

(4)Intent(意向):Activity之间的粘合剂。

使用Intent,可以在系统范围内向目标活动或者服务广播消息,说明希望执行某个动作的意图。

之后系统就会确定那些最适合执行动作的目标。

(5)Notification(通知):一种用户通知框架。

通过允许向用户发送信号,而不会过分吸引他们的注意力或者打断他们当前的活动。

它们是服务或者广播接收器吸引用户注意的首选方法。

例如,当设备接收到一个文本消息或者来电的时候,它可以通过闪灯、发出声音、显示图标或则会显示对话框信息的方式提示用户。

(6)Intent Receiver(意向接收器):通过Intent Receiver实现应用能够对一个外部的事件作出响应,Intent Receiver在AndroidManifest.xml中注册,但也可以在代码中使用Context.registerReceiver()进行注册。

当一个intent receive被触发时,应用不必对请求调用intent receive,系统会在需要的时候启动你的应用。

各种应用还可以通过使用Context.broadcastIntent()将它们自己的intent receive广播给其他应用程序。

3.2功能的具体实现(1)计算器布局设计:分别实用Button按钮操作17个按钮,分别是+、—、*、/、=、0-9、清除按钮,以及EditTest的文本域,并通过代码布局调整布局,使布局更加清晰,简洁。

布局方式如图所示:代码实现如下:<RelativeLayoutxmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity"><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:layout_marginTop="17dp"android:ems="10"/><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/editText1"android:layout_below="@+id/editText1"android:layout_marginTop="30dp"android:text="1"/><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button1"android:layout_alignBottom="@+id/button1"android:layout_toRightOf="@+id/button1"android:text="2"/><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button2"android:layout_alignBottom="@+id/button2"android:layout_toRightOf="@+id/button2"android:text="3"/><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/button1"android:text="4"/><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button4"android:layout_alignBottom="@+id/button4"android:layout_alignLeft="@+id/button2"android:text="5"/><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button3"android:layout_toRightOf="@+id/button5"android:text="6"/><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button4"android:layout_toLeftOf="@+id/button5"android:text="7"/><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button7"android:layout_alignBottom="@+id/button7"android:layout_alignLeft="@+id/button5"android:text="8"/><Buttonandroid:id="@+id/button9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button8"android:layout_alignBottom="@+id/button8"android:layout_toRightOf="@+id/button5"android:text="9"/><Buttonandroid:id="@+id/button10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button7"android:layout_below="@+id/button7"android:text="0"/><Buttonandroid:id="@+id/button11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button7"android:layout_toRightOf="@+id/button7"android:text="."/><Buttonandroid:id="@+id/button12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button11"android:layout_alignBottom="@+id/button11"android:layout_alignLeft="@+id/button9"android:text="="/><Buttonandroid:id="@+id/button13"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBottom="@+id/button3"android:layout_toRightOf="@+id/button3"android:text="+"/><Buttonandroid:id="@+id/button14"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button6"android:layout_alignBottom="@+id/button6"android:layout_toRightOf="@+id/button6"android:text="-"/><Buttonandroid:id="@+id/button15"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button12"android:layout_alignLeft="@+id/button14"android:text="*"/><Buttonandroid:id="@+id/button16"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button9"android:layout_toRightOf="@+id/button9"android:text="/"/><Buttonandroid:id="@+id/button17"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignRight="@+id/button16"android:layout_below="@+id/button11"android:text="清除" /></RelativeLayout>(2)计算功能实现加法实现:从editTest中获取数字赋值于num1,等待数字num2的输入。

相关文档
最新文档