zoukankan      html  css  js  c++  java
  • 实验5 数独游戏界面设计

    实验报告

    课程名称

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

    实验日期

    2016年4月14日

    实验项目名称

    数独游戏界面设计

    实验地点

    S3010

    实验类型

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

    学  时

    2

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

    1. 实现数独游戏的完整界面设计。
    2. 掌握ActionBar的使用。

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

    (1)PC机

    (2)操作系统:Windows XP

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

    三、实验内容及步骤

    1)  使用ActionBar显示OptionMenu的菜单项MenuItem;

    2)  使用程序图标导航;

    3)  添加Action View;

    4)  导入工程Sodoku ;

    5)  添加Activity类;

    6) 添加layout资源文件。

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

    About activity:

    package com.example.sukodu;
    
    import org.apache.http.impl.conn.DefaultClientConnection;
    
    import android.annotation.SuppressLint;
    import android.app.ActionBar;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    
    public class AboutActivity extends Activity {
        @SuppressLint("NewApi") @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.about);
            ActionBar abar =getActionBar();
            abar.setDisplayShowHomeEnabled(true);
            abar.setDisplayHomeAsUpEnabled(true);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            getMenuInflater().inflate(R.menu.actionbar, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            Intent intent=getIntent();
            switch(item.getItemId()){
            case android.R.id.home:
    //            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //            startActivity(intent);
                finish();
                break;
            case R.id.help :
                intent.setClass(this, HelpActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.newgame :
                intent.setClass(this, GamesActivity.class);
                startActivity(intent);
                finish();
                break;
            
            default :{
                break;
            }
            }
            return super.onOptionsItemSelected(item);
        }
    }

    Help activity:

    package com.example.sukodu;
    
    import android.annotation.SuppressLint;
    import android.app.ActionBar;
    import android.app.Activity;
    import android.content.Intent;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class HelpActivity extends Activity {
    
        
        @SuppressLint("NewApi") public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.help);
            ActionBar abar = getActionBar();
            abar.setDisplayShowHomeEnabled(true);
            abar.setDisplayHomeAsUpEnabled(true);
            
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            getMenuInflater().inflate(R.menu.actionbar, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            Intent intent = getIntent();
            switch (item.getItemId()) {
            case android.R.id.home: {
                finish();
                break;
            }
            case R.id.about: {
                intent.setClass(this, AboutActivity.class);
                startActivity(intent);
                finish();
                break;
            }
            case R.id.newgame :{
                intent.setClass(this, GamesActivity.class);
                startActivity(intent);
                finish();
                break;
            }
            default:{
                break;
            }
            }
            return super.onOptionsItemSelected(item);
        }
    }

    Main sctivity:

    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            getMenuInflater().inflate(R.menu.actionbar, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            Intent it = new Intent();
            switch (item.getItemId()) {
            case R.id.itemRed:
                titleview.setTextColor(Color.RED);
                break;
            case R.id.itemGreen:
                titleview.setTextColor(Color.GREEN);
                break;
            
                
            case R.id.help: {
                it.setClass(this, HelpActivity.class);
                startActivity(it);
                break;
            }
            case R.id.about: {
                it.setClass(this, AboutActivity.class);
                startActivity(it);
                break;
            }
            case R.id.newgame: {
                it.setClass(this, GamesActivity.class);
                startActivity(it);
                break;
            }
            
            default:{
                break;
            }
            }
            return super.onOptionsItemSelected(item);
        }

    Newgame activity:

    package com.example.sukodu;
    
    import android.annotation.SuppressLint;
    import android.app.ActionBar;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    
    public class GamesActivity extends Activity{
        @SuppressLint("NewApi") public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.games);
            ActionBar abar =getActionBar();
            abar.setDisplayShowHomeEnabled(true);
            abar.setDisplayHomeAsUpEnabled(true);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            getMenuInflater().inflate(R.menu.actionbar, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            Intent intent = getIntent();
            switch(item.getItemId()){
            case android.R.id.home:{
                finish();
                break;
            }
            case R.id.about: {
                intent.setClass(this, AboutActivity.class);
                startActivity(intent);
                finish();
                break;
            }
            case R.id.help :{
                intent.setClass(this, HelpActivity.class);
                startActivity(intent);
                finish();
                break;
            }
            
            default:{
                break;
            }
            }
            return super.onOptionsItemSelected(item);
        }
        
    }

    About layout:

    package com.example.sukodu;
    
    import org.apache.http.impl.conn.DefaultClientConnection;
    
    import android.annotation.SuppressLint;
    import android.app.ActionBar;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    
    public class AboutActivity extends Activity {
        @SuppressLint("NewApi") @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.about);
            ActionBar abar =getActionBar();
            abar.setDisplayShowHomeEnabled(true);
            abar.setDisplayHomeAsUpEnabled(true);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
            getMenuInflater().inflate(R.menu.actionbar, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            Intent intent=getIntent();
            switch(item.getItemId()){
            case android.R.id.home:
    //            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //            startActivity(intent);
                finish();
                break;
            case R.id.help :
                intent.setClass(this, HelpActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.newgame :
                intent.setClass(this, GamesActivity.class);
                startActivity(intent);
                finish();
                break;
            
            default :{
                break;
            }
            }
            return super.onOptionsItemSelected(item);
        }
    
    }

    Clock:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <AnalogClock
            android:id="@+id/analogClock1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>

    Help layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="30sp" >
    
        <TextView
            android:id="@+id/help_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/help_title"
            android:textSize="30sp" />
    
        <TextView
            android:id="@+id/help_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/help_jieshao"
            android:textSize="15sp" />
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/help" />
        
    </LinearLayout>

    Newgame layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/game"
        android:orientation="vertical" >
        
    </LinearLayout>

    运行结果:(截图)

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

        对于新知识的运用还不够熟练,要多加练习。

  • 相关阅读:
    每一个合格的家庭主妇都是生产厂长的有力竞争者
    单点登录在ASP.NET上的简单实现
    Asp.net(C#)给图片加上水印效果
    Asp.net Ajax框架教程
    记入cookie一个ip一天只弹一次的弹窗代码JavaScript实例教程
    【转】ASP.net2。0中解决无法获取 GridView 隐藏列值问题
    javascript 动态添加表格行
    IndexOf方法,LastIndexOf方法,substring方法
    SQL 批量插入数据
    js 前台找控件(table里找控件)
  • 原文地址:https://www.cnblogs.com/zzen/p/5393726.html
Copyright © 2011-2022 走看看