目前分類:上課筆記 (32)

瀏覽方式: 標題列表 簡短摘要

WelcomeActivity01WelcomeActivity02  


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

Dialog01Activity01Dialog01Activity02Dialog01Activity03MainActivity01MainActivity02  


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

FruitAdapter01Spinner01Activity

 

Main Activity.java

 

package com.CodersCafe.www;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {
private RadioGroup sizerg;
private RadioGroup icerg;

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

用Command line安裝APK

新增多國語系

如果修改.xml之後,紅線遲遲不消,進"Project"=>"Clean"=>"Clean selected below"=>"Build only the selected projects"要求AAPT重新Build

 

project.properties內:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

即可開啟ProGuard程式混淆器,會將Private的變數替代為別的代號。增加閱讀難度,還可以減少程式碼長度

 

 

MainActivity01MultiLanguage01MultiLanguage02MultiLanguage03MultiLanguage04  

 

原始碼: (仍有}問題,尚無法執行)

package com.CodersCafe.www;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

Main Activity 一版

MainActivity01

Main Activity 二版

MainActivity02

Cafe.java

Cafe03  

Order.java

Order03  

 

原始碼:

Main Activity:

(cafebtn尚有問題)

package com.CodersCafe.www;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

 

尚未完成Main Activity.java:

package com.CodersCafe.www;

import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

;

public class MainActivity extends Activity {
private RadioGroup sizerg;
private RadioGroup icerg;
private RadioGroup sugarrg;
private RadioButton[] sizerb = new RadioButton[3];
private RadioButton[] icerb = new RadioButton[5];
private RadioButton[] sugarrb = new RadioButton[5];

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

MainActivity01MainActivity02MainActivity03  


鈴木保齡球 發表在 痞客邦 留言(1) 人氣()

匯入Android專案程式碼:

File>Import>Android>Exist Android Code (Copy)

如有更動XML,建議清除AAPT建立之檔案重新Build:

Project>Clean

 

AVD設定(使用含有Google Service之Google APIs)

AVD

原始碼-1

MainActivity01  

執行結果:

TextView>Auto Link>all (自動辨識)

android:textAppearance="?android:attr/textAppearanceLargeSmall" //設為小字,會依據解析度自動調整

20141217-2  

 

GenyMotion Android模擬器

https://www.genymotion.com/

 

程式碼:

package com.example.bmi;

import android.os.Bundle;

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

建立執行緒步驟:

第一種作法 :
1. 撰寫Thread的子類別, 並override run() method
2. new 步驟1的class之實體
3. 呼叫步驟2實體中的start()

第二種作法 :
1. 撰寫一新類別並實作java.lang.Runnable介面
2. new Thread(new 步驟1的class之實體)
3. 呼叫步驟2實體中的start()

 

ThreadTestMain.java

package com.hellopianoman.thread;

public class ThreadTestMain {
    public static void main(String[] args) {
        ShowDataThread showDataThread = new ShowDataThread();
        showDataThread.start();

        GetDataThread getDataThread = new GetDataThread(showDataThread);
        getDataThread.start();
    }
}

鈴木保齡球 發表在 痞客邦 留言(1) 人氣()

(51) Click the exhibit button.
1. import java.io.IOException;
2. public class ExceptionTest{
3.  public static void main(String[] args){
4.   try {
5.    methodA();
6.   } catch (IOException e){
7.    System.out.println("Caught IOException");
8.   } catch (Exception e){
9.    System.out.println("Caught Exception"); 
10.  }
11.  }
12.  public void methodA (){
13.   throw new IOException ();
14.  }
15.}

What is the result?


A. The code will not compile.
B. The output is Caught Exception.

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

EnableLogCatMainActivity01NewProject01NewProject02NewProject03NewProject04NewProject05NewProject06  


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

 申請免費網站空間,靜態網頁+SQL: www.000webhost.com

我們的網站: http://coderspace.webatu.com/

未來package name就可以設成: com.webatu.coderspace.androidTest (package name)

xml name space: 這個名字=真正的本尊

 

Uniform Resource Identifier => 協定://資源持有單位/資源第一層分類/.../第n層分類/資源名稱

統一       資源          識別

URLocation

 

@ = 對系統說的話

@口 = 查詢

MainActivity01

MainActivity02  

 


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

Android程式開發實務

第一堂課(2014.12.08) JJ Lin老師

 

Windows 環境設定

新增環境變數JAVA_HOME

新增環境變數CLASSPATH

編輯環境變數PATH

Eclipse 環境設定

使用老師的ADK懶人包,僅安裝需要的Android模擬器檔案

Android Virtual Device (AVD) 設定範例

AVD01  AVD2

練習在兩台虛擬機內傳簡訊、打電話。

後續建議用USB線連接實機,Eclipse 右上方新增DDMS面板

AVD2  


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

Q1. 某大學為因應國際化趨勢將採用歐美國家使用的「等第制」計分法, 目前需要一個程式能將「百分制」轉成「等第制」並在螢幕上顯示,
請在下面的showGrade方法中寫上程式碼, 並達到以下要求 :
如果傳入的分數參數為80~100則在螢幕上顯示A,
如果傳入的分數參數為70~79則在螢幕上顯示B,
如果傳入的分數參數為60~69則在螢幕上顯示C,
如果傳入的分數參數為50~59則在螢幕上顯示D,
如果傳入的分數參數為0~49則在螢幕上顯示E

public class ScoreUtil {
    public static void showGrade(int score) {

   }
}

嘗試一:

package javaapplication1;

import java.util.Scanner;

public class ScoreUtil {

    public static void showGrade(int score) {

       Scanner scanner = new Scanner (System.in);
       
        switch (level) {

            case 1:

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

 

Java程式錯誤分為Error和Exception,通常不處理Error,只對Exception作處理。

範例一: 帶有錯誤的java程式碼

import java.io.*;

public class ReadInput2 {
  public static void main(String[] args) {
      int no1 = input("請輸入分子");
      int no2 = input("請輸入分母");
      System.out.println(no1+"/"+no2+"="+(no1/no2));
  }

  public static int input(String message) {
      System.out.println(message);
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int a=Integer.parseInt(in.readLine());
      return a;
  }
}

錯誤訊息是: Unreported IOException

 

方法一: 直接加try, catch 解決問題

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

public class Star {
    private String name;
    private int height;

    public Star(String name, int height) {
         this.name=name;
         this.height=height;
    }

    @Override
    public int hashCode() { //此method宣告格式要背,考試會考
        // 正確的雜湊碼實作須符合兩大規則
        //  1. 需使用hashCode()所在的那個class內的屬性為計算基礎
        //  2. 在相配合的equals()中沒有參加比對相等性的屬性不能參加雜湊碼計算
        return this.height+name.hashCode();
    }


    @Override
    public boolean equals(Object obj) { //此method宣告格式要背,考試會考
        if(obj instanceof Star){
            Star s = (Star)obj;
            if(name.equals(s.name) && height==s.height)

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

public class Outside {
static String out_a = "Outside class string 1";
String out_b = "Outside class string 2";
public static void main(String[] args) {
Inner1 a = new Outside().new Inner1();
Outside.Inner1 b = new Outside().new Inner1();
Inner1 c = new Inner1(); //錯誤,因Inner1 是動態故需先建立他所在的class Outside 之實體
Inner2 d = new Outside().new Inner2(); // error
Outside.Inner2 e = new Outside().new Inner2(); //錯誤,此語法只適用在動態內部類別
Inner2 f = new Inner2(); //,因Inner2 是靜態故不需先建立他所在的class Outside 之實體
Inner1 g =this.new Inner1(); // 錯誤, this 或super 指令不能出現在靜態範圍裡
System.out.println(Outside.Inner2.inner2_a);
}
Outside( ) {
Inner1 a = new Inner1( );
Inner1 b = this.new Inner1( ); // this.後不能接new 指令
Inner2 c = new Inner2( );
Inner2 d = new Outside.Inner2();
Inner2 e = this.new Inner2( ); // this.後不能接new 指令
}

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

P.94

Method signature (Method 特徵)包含:

method名稱
參數數量
參數資料型態
參數前後順序

 

P.95

一般在收參數時,會寫成這樣:

public float average(int x1, intx2){}

但如果一次要收多個參數,可以寫成:

 

P.111

子類別可覆寫父類別,前提是:

  • 靜動態宣告, method名稱, 參數數量、參數型態、參數順序需與父類別相同    //Extend父類別之後,完全照抄父類別METHOD,那一定可以覆寫
  • 存取權限與能與父類別相同或更大                                 //或是最前面的權限形容詞private, 則子類別用public可覆寫
  • 回傳值型態如果是基本型態則須與父類別相同, 如果回傳值是物件型態, 則可與父類別回傳值相同或更小      //父類別是Object, 子類別是String可覆寫
  • 子類別method拋出的應檢核例外需與父類別應檢核例外相同或更小, 非檢核例外則可與父類別相同或不同   

 

Overload(多載)考題:

 

(8) Given:

1. public class ConstOver {
2. public ConstOver(int x, int y, int z){

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

Eric老師推薦安裝MyEclipse+TomCat7+HTTP Watch來開發Java Web Project

 

網頁Server運作原理:

本機首先查詢本機host檔案有無查詢的網址,如果有便直接帶到網站。如果沒有,會對網路DNS Server發出Header訊息(檔頭),DNS向該網站確認是否存在,確認之後帶到該網站。

網站會在向後端資料庫詢問是否有index.jsp OR index.html等網頁(記載在web.xml內)

UML  

JSP網頁主要就是在寫上圖Yahoo網站到SQL的這一部分。


鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

String a = "Java SCJP";
System.out.println(a.length());  // 取得字串長度, 印出 9    
byte[] b = {74, 97, 118, 97, 20, 83, 67, 74, 80};
String c = new String(b);
System.out.println(c);  // 印出 Java SCJP
String d = new String(b, 0, 4);
System.out.println(d);  // 印出 Java
char[] e = {'J', 'a', 'v', 'a', ' ', 'S', 'C', 'J', 'P'};
String f = new String(e);
System.out.println(f);  // 印出 Java SCJP
String g = new String(e, 5, 4);
System.out.println(g);  // 印出 SCJP
String h = new String(a);
System.out.println(h);  // 印出 Java SCJP
StringBuffer i = new StringBuffer("Java"); // 字串內容可以直接修改, 速度較String快    buffer緩衝區
System.out.println(i);  // 印出 Java
StringBuilder sb = new StringBuilder("Java"); // 字串內容可以直接修改, 速度較String及StringBuffer快
System.out.println(sb);  // 印出 Java
String j = new String(i);
System.out.println(j);  // 印出 Java

鈴木保齡球 發表在 痞客邦 留言(0) 人氣()

1 2