20192307 2020-2021-1 《数据结构与面向对象程序设计》实验五报告
20192307 2020-2021-1 《数据结构与面向对象程序设计》实验五报告
- 课程:《数据结构与面向对象程序设计》
- 班级: 1923
- 姓名: 常万里
- 学号: 20192307
- 实验教师:王志强老师
- 实验日期:2020年10月29日
- 必修/选修: 必修
一、实验内容
- 1.Android Stuidio的安装测试:
参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:
参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio
完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号
学习Android Stuidio调试应用程序- 2.Activity测试
参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
构建项目,运行教材相关代码
创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity- 3.UI测试
参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
构建项目,运行教材相关代码
修改代码让Toast消息中显示自己的学号信息- 4.布局测试:
参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
构建项目,运行教材相关代码
修改布局让P290页的界面与教材不同- 5.事件处理测试:
参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
构建项目,运行教材相关代码
二、实验过程及结果
(一)Android Stuidio的安装测试
MainActivity
package com.example.myapplication1;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
private Button juice;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
juice = findViewById(R.id.button1);
juice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"We Are Never Ever Getting Back Together",Toast.LENGTH_LONG).show();
}
});
}
}
运行结果截图
(二)Activity测试
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activitydemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ActivityDemo">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:label="@string/app_name"
android:theme="@style/Theme.ActivityDemo.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity
package com.example.activitydemo;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button juice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("lifecycle","onCreate");
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
juice = findViewById(R.id.button3);
juice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"We Are Never Ever Getting Back Together",Toast.LENGTH_LONG).show();
}
});
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "My email address is 1035564567@qq.com", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public void onStart(){
super.onStart();
Log.d("lifecycle","onStart");
}
@Override
public void onRestart(){
super.onRestart();
Log.d("lifecycle","onReStart");
}
@Override
public void onResume(){
super.onResume();
Log.d("lifecycle","onResume");
}
@Override
public void onPause(){
super.onPause();
Log.d("lifecycle","onPause");
}
@Override
public void onStop(){
super.onStop();
Log.d("lifecycle","onStop");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.d("lifecycle","onDestroy");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
运行结果截图
(三)UI测试
package com.example.mytoast;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button justtry;
private Button toastry;
private Button juice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
justtry = findViewById(R.id.button2);
justtry.setOnClickListener(new View.OnClickListener() {
class secondactivity {
}
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,secondactivity.class);
startActivity(intent);
}
});
toastry = findViewById(R.id.button3);
toastry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Hello 20192307常万里\nHave a Nice Day!",Toast.LENGTH_LONG).show();
}
});
juice = findViewById(R.id.button4);
juice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"We Are Never Ever Getting Back Together",Toast.LENGTH_LONG).show();
}
});
}
}
运行结果截图
(四)布局测试
XML代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="@drawable/main_background"
tools:context=".MainActivity">
<TextView
android:layout_width="272dp"
android:layout_height="205dp"
android:text=" Hello World!\n 20192306孙洪丽\n 20192307常万里\n 20192308王泽荣"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.359"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.192" />
<Button
android:id="@+id/button1"
android:text="戳我戳我"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:layout_marginLeft="100dp"/>
<ImageButton
android:id="@+id/button2"
android:layout_width="71dp"
android:layout_height="66dp"
android:layout_marginLeft="@dimen/cardview_compat_inset_shadow"
android:layout_marginTop="160dp"
android:alpha="0.35"
android:contentDescription="TODO"
android:src="@android:drawable/btn_star_big_on" />
</FrameLayout>
运行结果截图
(五)事件处理测试
MainActivity
package com.example.myapplication1;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
private Button juice;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
juice = findViewById(R.id.button1);
juice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"We Are Never Ever Getting Back Together",Toast.LENGTH_LONG).show();
}
});
}
}
三、实验过程中遇到的问题和解决过程
- 问题1:没遇到啥问题,这次实验挺简单的。
四、心得体会
- 在这次实验过程中,我遇到了许多问题,其中既有知识上的漏洞,也有不细心导致的马虎,这一切都补充,完善,丰富,扩展了我的计算机知识体系。在不断修复问题的过程中,我使用了很多方式去查询资料,例如:《数据结构与面向对象程序设计》,博客园平台,CSDN平台,码云平台,知乎app,等。进一步熟悉了Android studio这个平台的使用与运行方式,提高了自己自主学习的能力,为我接下来学习数据结构以及JAVA语言程序设计打下了坚实的基础,并在不断探索的过程中逐步提升了自己。