安卓计算器开发实验报告.docx

上传人:b****4 文档编号:24401005 上传时间:2023-05-27 格式:DOCX 页数:30 大小:491.47KB
下载 相关 举报
安卓计算器开发实验报告.docx_第1页
第1页 / 共30页
安卓计算器开发实验报告.docx_第2页
第2页 / 共30页
安卓计算器开发实验报告.docx_第3页
第3页 / 共30页
安卓计算器开发实验报告.docx_第4页
第4页 / 共30页
安卓计算器开发实验报告.docx_第5页
第5页 / 共30页
点击查看更多>>
下载资源
资源描述

安卓计算器开发实验报告.docx

《安卓计算器开发实验报告.docx》由会员分享,可在线阅读,更多相关《安卓计算器开发实验报告.docx(30页珍藏版)》请在冰豆网上搜索。

安卓计算器开发实验报告.docx

安卓计算器开发实验报告

上海电力学院

嵌入式WebOS应用开发

实验报告

实验名称:

 使用AndroidDeveloperSDK开发应用程序

  专  业:

      

姓名:

          

班级:

    

学号:

      

一、作品得运行环境及安卓SDK基础操作

SDKAndroid Developer就是一款在windows系统上运行得针对Android应用开发得谷歌官方软件(需要JAVA环境支持).

1、导入工程

 

2、建立虚拟机

 

  

在运行虚拟机就是为保证机器得顺畅运行建议选择分辨率较低得虚拟机,但就是其RAM最好设为512MB,因为部分程序如果调用资源过大会导致虚拟机无法运行。

3、虚拟机界面

二、作品介绍

我得应用就是一个计算器。

能实现包括小数得加减乘除运算,结果过大会自动用科学记数法表示,另外还有退格跟清屏功能键。

三、编程以及运行调试

(一)、在MyDesktop主界面中添加应用图标

1、首先在我得桌面上添加您应用得图标以及文字,双击图标后就可以瞧见对应得代码,可直接在代码中进行修改图片文字得大小颜色等等.

以下就是对应图像图标得代码

图片可以在左侧得选

项中自行进行挑选;

也可以添加自己得图片,

只要将图片放到对应得

文件夹之下在刷新就可

以,但不建议放分辨率

过高图片可能会出现超

出界面得等错误。

(二)、在res/layout目录下新建、xml文件,由于计算器得按钮很多,要在xml界面中添加排版:

 

xml代码首末得</AbsoluteLayout〉格式较为自由可以直接在界面中拖动图标位置以及修改大小,而其她layout则更会自动排列,各有优劣。

(三)、在src/weibo、test、ui目录下新建、java文件,计算器得按钮算法等都在此实现。

(三)、声明工程名

1、在应用中有三处需要声明,首先就是在AndroidManifest、xml

2、然后就是在MainActivity、java

四、代码展示

(一)、、xml界面代码

<?

xmlversion="1、0" encoding="utf-8"?

>

〈LinearLayoutxmlns:

android=""

  android:

layout_width="fill_parent"

   android:

layout_height=”fill_parent"

 android:

orientation="vertical" 〉

 〈TableLayout

    android:

id=”+id/tableLayout1"

 android:

layout_width="match_parent"

   android:

layout_height="wrap_content"

 android:

collapseColumns="4”>

  <TableRow

  android:

id="+id/tableRow_et"

    android:

layout_width="fill_parent”

    android:

layout_height="fill_parent">

  〈EditText

   android:

id="+id/et"

    android:

layout_width="fill_parent"

    android:

layout_height="fill_parent"

  android:

layout_span=”4”

   android:

focusable=”false"

 android:

gravity=”right"

  android:

inputType=”text”

       android:

singleLine="true"〉

     

  

   <TableRow

     android:

id="+id/tableRow1"

 android:

layout_width="fill_parent"

    android:

layout_height="fill_parent” >

     <Button

  android:

id="+id/bt_7”

     android:

layout_width="80px"

      android:

layout_height="80px"

      android:

text="7"/>

   <Button

    android:

id="+id/bt_8"

       android:

layout_width="80px"

   android:

layout_height=”80px"

      android:

text="8”/>

     〈Button

    android:

id="+id/bt_9”

    android:

layout_width=”1px"

    android:

layout_height=”80px”

   android:

text=”9”/>

     android:

id="+id/bt_back"

    android:

layout_width=”80px"

     android:

layout_height="80px"

   android:

text="back"/〉

  〈TableRow

     android:

id=”+id/tableRow2"

    android:

layout_width=”fill_parent"

     android:

layout_height="fill_parent" >

    <Button

      android:

id="+id/bt_4”

   android:

layout_width=”80px"

 android:

layout_height="80px"

    android:

text=”4"/>

 

  android:

id="+id/bt_5"

      android:

layout_width="80px"

   android:

layout_height="80px"

    android:

text=”5”/>

  <Button

       android:

id="+id/bt_6”

     android:

layout_width="80px”

    android:

layout_height="80px"

     android:

text="6"/>

    

  android:

id="+id/bt_divide"

 android:

layout_width="80px"

   android:

layout_height="80px"

    android:

text=”/”/〉

<TableRow

   android:

id=”+id/tableRow3”

   android:

layout_width="fill_parent"

     android:

layout_height="fill_parent"〉

  〈Button

    android:

id=”+id/bt_1"

  android:

layout_width=”80px"

    android:

layout_height="80px"

     android:

text="1” />

    <Button

     android:

id=”+id/bt_2"

  android:

layout_width="80px”

    android:

layout_height="80px”

   android:

text="2" />

   

    android:

id=”+id/bt_3"

    android:

layout_width=”80px"

       android:

layout_height="80px"

   android:

text="3" /〉

   〈Button

     android:

id=”+id/bt_multiply"

    android:

layout_width=”80px”

    android:

layout_height="80px"

   android:

text="*”/>

 </TableRow>

 <TableRow

   android:

id="+id/tableRow4”

 android:

layout_width="fill_parent"

   android:

layout_height=”fill_parent” 〉

  〈Button

   android:

id=”+id/bt_0"

    android:

layout_width=”50px”

 android:

layout_height=”80px"

      android:

text="0"/〉

    <Button

     android:

id=”+id/bt_point"

   android:

layout_width=”50px"

 android:

layout_height=”80px"

    android:

text="、"/>

   <Button

      android:

id=”+id/bt_add”

  android:

layout_width="50px"

    android:

layout_height=”80px"

    android:

text="+"/〉

   <Button

      android:

id=”+id/bt_sub"

 android:

layout_width=”50px"

   android:

layout_height="80px"

   android:

text=”—"/〉

  

 

 android:

id="+id/tableRow4"

  android:

layout_width="fill_parent"

   android:

layout_height=”fill_parent”>

   

   android:

id=”+id/bt_equal"

   android:

layout_width="fill_parent”

 android:

layout_height=”fill_parent”

   android:

layout_span="3"

      android:

text="=" />

    <Button

     android:

id=”+id/bt_clear"

    android:

layout_width=”50px"

   android:

layout_height=”80px"

  android:

text="clear”/>

   </TableRow〉

(二)、、java功能代码

packageweibo、test、ui;

importjava、util、ArrayList;

importjava、util、List;

importandroid、app、Activity;

importandroid、os、Bundle;

import android、view、View;

importandroid、view、View、OnClickListener;

importandroid、widget、Button;

importandroid、widget、EditText;

importandroid、widget、Toast;

import weibo、lixiaodaoaaa、ui、R;

importandroid、app、Activity;

import android、content、Intent;

import android、content、pm、PackageManager;

importandroid、os、Bundle;

importandroid、view、KeyEvent;

import android、view、View;

importandroid、view、View、OnClickListener;

importandroid、widget、Button;

importandroid、widget、ListView;

import、zsy、flipper、AppInfUtil;

import 、zsy、flipper、AppInfo;

publicclassfffActivityextends Activity  

{

private Buttonbt_1;

privateButtonbt_2;

ﻩprivateButtonbt_3;

privateButtonbt_4;

ﻩprivateButton bt_5;

privateButtonbt_6;

ﻩprivateButtonbt_7;

private Buttonbt_8;

privateButtonbt_9;

privateButtonbt_0;

private Buttonbt_add;

ﻩprivateButton bt_sub; //减

privateButtonbt_multiply; //乘

privateButton bt_divide;//除

ﻩprivateButton bt_back;

ﻩprivateButtonbt_equal;// 等于

private Buttonbt_point; //点

ﻩprivateButtonbt_clear; //清除

privateEditTextet_play; // 显示

privateStringstr_oper="+”; //运算符

privateStringBufferstr_display=new StringBuffer();;//显示

ﻩprivate Stringstr_result;//结果显示

ﻩprivatedoublenum1;

ﻩprivatedouble num2;

privateboolean flag=true; // 小数点个数开关控制;

ﻩprivatebooleanb_sub,b_mul,b_div;//运算符开关控制

Override

publicvoid onCreate(BundlesavedInstanceState)

{

ﻩsuper、onCreate(savedInstanceState);

setContentView(R、layout、activity_fff);

ﻩbt_0 =(Button)findViewById(R、id、bt_0);

ﻩﻩbt_1= (Button)findViewById(R、id、bt_1);

bt_2=(Button)findViewById(R、id、bt_2);

ﻩbt_3=(Button)findViewById(R、id、bt_3);

bt_4=(Button)findViewById(R、id、bt_4);

ﻩbt_5=(Button)findViewById(R、id、bt_5);

bt_6= (Button)findViewById(R、id、bt_6);

bt_7=(Button) findViewById(R、id、bt_7);

ﻩbt_8=(Button)findViewById(R、id、bt_8);

bt_9 =(Button) findViewById(R、id、bt_9);

bt_add =(Button)findViewById(R、id、bt_add);

ﻩﻩbt_sub=(Button)findViewById(R、id、bt_sub);

ﻩbt_multiply = (Button)findViewById(R、id、bt_multiply);

ﻩbt_divide= (Button)findViewById(R、id、bt_divide);

bt_back=(Button)findViewById(R、id、bt_back);

ﻩbt_equal= (Button)findViewById(R、id、bt_equal);

ﻩbt_point=(Button) findViewById(R、id、bt_point);

ﻩbt_clear=(Button)findViewById(R、id、bt_clear);

ﻩet_play=(EditText)findViewById(R、id、et);

ﻩﻩet_play、setText("0”);

ﻩbt_0、setOnClickListener(new OnClickListener()

ﻩ{

ﻩﻩOverride

ﻩpublicvoidonClick(View v)

ﻩﻩﻩ{

str_display、append("0”);

ﻩﻩﻩet_play、setText(str_display、toString());

ﻩ}

ﻩ});

ﻩbt_1、setOnClickListener(newOnClickListener()

ﻩ{

Override

ﻩﻩpublicvoidonClick(Viewv)

ﻩﻩ{

ﻩﻩﻩstr_display、append("1");

ﻩﻩﻩet_play、setText(str_display、toString());

}

ﻩﻩ});

ﻩbt_2、setOnClickListener(newOnClickListener()

ﻩ{

ﻩOverride

ﻩﻩpublic voidonClick(Viewv)

ﻩﻩ{

ﻩﻩstr_display、append("2");

ﻩﻩﻩﻩet_play、setText(str_display、toString());

ﻩ}

});

ﻩﻩbt_3、setOnClickListener(new OnClickListener()

ﻩ{

ﻩOverride

publicvoidonClick(Viewv)

ﻩﻩ{

ﻩﻩstr_display、append("3");

ﻩet_play、setText(str_display、toString());

ﻩ}

ﻩ});

ﻩbt_4、setOnClickListener(newOnClickListener()

ﻩ{

ﻩﻩOverride

ﻩﻩpublicvoid onClick(View v)

ﻩﻩﻩ{

ﻩﻩstr_display、append("4”);

ﻩﻩet_play、setText(str_display、toString());

ﻩ});

ﻩﻩbt_5、setOnClickListener(newOnClickListener()

ﻩ{

ﻩOverride

publicvoidonClick(Viewv)

ﻩ{

ﻩﻩstr_display、append("5");

ﻩﻩet_play、setText(str_display、toString());

});

bt_6、setOnClickListener(newOnClickListener()

{

ﻩOverride

ﻩpublicvoidonClick(Viewv)

{

ﻩstr_display、append("6");

ﻩﻩet_play、setText(str_display、toString());

ﻩﻩ}

ﻩﻩ});

ﻩbt_7、setOnClickListener(newOnClickListener()

ﻩ{

ﻩﻩOverride

ﻩﻩpublic void onClick(Viewv)

ﻩ{

ﻩﻩstr_display、append(”7");

ﻩet_play、setText(str_display、toString());

ﻩ}

ﻩﻩ});

ﻩﻩbt_8、setOnClickListener(newOnClickListener()

ﻩﻩ{

ﻩﻩﻩOverride

ﻩﻩpublic void onClick(View v)

ﻩﻩ{

ﻩﻩﻩstr_display、append("8");

ﻩﻩet_play、setText(str_display、toString());

ﻩﻩ}

});

ﻩﻩbt_9、setOnClickListener(new OnClickListener()

ﻩﻩOverride

ﻩﻩﻩpublicvoidonClick(Viewv)

ﻩstr_display、append("9”);

et_play、setText(str_display、toString());

});

bt_point、setOnClickListener(newOnClickListener()

{

ﻩﻩﻩOverride

ﻩﻩﻩpublic void onClick(View v)

ﻩif(flag)

ﻩﻩ

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1