您的位置:首页 > 其它

实验5 数独游戏界面设计

2016-04-15 13:09 169 查看

课程名称

基于Android平台移动互联网开发

实验日期

2016年4月15日

实验项目名称

设计一个简单登陆界面

实验地点

S3010

实验类型

□验证型    √设计型    □综合型

学  时

4

一、实验目的及要求(本实验所涉及并要求掌握的知识点)

1目的:实现数独游戏的完整界面设计

2要求:掌握ActionBar的使用

二、实验环境(本实验所使用的硬件设备和相关软件)

(1)PC机

(2)操作系统:Windows XP

(3)软件: Eclipse, JDK1.6,Android SDK,ADT

三、实验内容及步骤

1)   导入工程Sodoku

2)   添加以下的Activity类

3)   添加以下layout资源文件

4)   完成设计后,界面运行如下

 

四、实验结果(本实验源程序清单及运行结果或实验结论、实验设计图)

代码:

package com.example.sudoku;

import com.example.sudoku.R.drawable;
import com.example.sudoku.R.layout;

import android.R.color;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

@SuppressLint("NewApi") public class MainActivity extends Activity {
private Button aboutbutBut,applyBut;
private Button exitBut;
private TextView TV1;
private LinearLayout  V;
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aboutbutBut = (Button) findViewById(R.id.about);
applyBut=(Button)findViewById(R.id.apply);
exitBut=(Button)findViewById(R.id.exit);
V=(LinearLayout)findViewById(R.id.LinearLayout1);
Bundle bundle=new Bundle();
bundle=getIntent().getExtras();
TV1=(TextView)findViewById(R.id.usernameTV);
TV1.setText("你的大名是:"+bundle.getString("username"));
actionBar=getActionBar();
actionBar.show();
aboutbutBut.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(MainActivity.this, about_main.class);
startActivity(intent);
MainActivity.this.finish();
}
});
exitBut.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this, login_main.class);
startActivity(intent);
MainActivity.this.finish();
}
});
applyBut.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this, apply_main.class);
startActivity(intent);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}

public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Resources resources;
Drawable btnDrawable;
item.setChecked(true);
switch (item.getItemId()) {
case R.id.ai1_1:
item.setChecked(true);
resources = getBaseContext().getResources();
btnDrawable = resources.getDrawable(R.drawable.ppp);
V.setBackground(btnDrawable);
break;
case R.id.ai1_2:
item.setChecked(true);
resources = getBaseContext().getResources();
btnDrawable = resources.getDrawable(R.drawable.p2);
V.setBackground(btnDrawable);
break;
case R.id.ai1_3:
item.setChecked(true);
resources = getBaseContext().getResources();
btnDrawable = resources.getDrawable(R.drawable.p4);
V.setBackground(btnDrawable);
break;
case R.id.ai1_4:
item.setChecked(true);
resources = getBaseContext().getResources();
btnDrawable = resources.getDrawable(R.drawable.p3);
V.setBackground(btnDrawable);
break;
case R.id.ai1_5:
item.setChecked(true);
resources = getBaseContext().getResources();
btnDrawable = resources.getDrawable(R.drawable.p5);
V.setBackground(btnDrawable);
break;
case R.id.ai2:
item.setChecked(true);
Intent intent=new Intent();
intent.setClass(MainActivity.this, music_main.class);
startActivity(intent);
break;
case R.id.ai3:
item.setChecked(true);
Intent intent1=new Intent();
intent1.setClass(MainActivity.this, help_main.class);
startActivity(intent1);
break;
case R.id.ai4:
item.setChecked(true);
Intent intent2=new Intent();
intent2.setClass(MainActivity.this, about_main.class);
startActivity(intent2);
case R.id.aix:
item.setChecked(true);
Intent intentx=new Intent();
intentx.setClass(MainActivity.this, newgame_main.class);
startActivity(intentx);

default:
break;
}
return super.onOptionsItemSelected(item);
}

}

 

 

运行结果:(截图)

 

 

 

 

 

五、实验总结(对本实验结果进行分析,实验心得体会及改进意见)

    经过本次的实验,我认为自己还有很多不足的地方,在实验过程中没有很好的独立完成,需要通过参考一些资料以及问同学的意见再结合之前的一些文档,但我也了解到了安卓应用的基本结构,对于如何该怎样编写一个简单的安卓应用有一定的了解。

实验评语

 

实验成绩

 

指导教师签名:              年   月   日

           

转载于:https://www.cnblogs.com/VernSean/p/5395038.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: