目前分類:上課筆記 (32)
- Jan 07 Wed 2015 20:28
[Android]Cafe App 練習 - 5
- Jan 07 Wed 2015 19:34
[Android] Cafe App 練習 - 4
- Dec 26 Fri 2014 19:59
[Android] Cafe App 練習 - 3
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;
- Dec 24 Wed 2014 20:09
[Android] Cafe App 練習 - 3
用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的變數替代為別的代號。增加閱讀難度,還可以減少程式碼長度
原始碼: (仍有}問題,尚無法執行)
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;
- Dec 22 Mon 2014 18:58
[Android] Cafe App 練習 - 2
Main Activity 一版
Main Activity 二版
Cafe.java
Order.java
原始碼:
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;
- Dec 19 Fri 2014 22:06
[Android] Cafe App 練習 - 1
尚未完成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];
- Dec 17 Wed 2014 20:44
[Android] BMI程式練習-1
- Dec 17 Wed 2014 19:45
[Android] BMI程式練習-2
匯入Android專案程式碼:
File>Import>Android>Exist Android Code (Copy)
如有更動XML,建議清除AAPT建立之檔案重新Build:
Project>Clean
AVD設定(使用含有Google Service之Google APIs)
原始碼-1
執行結果:
TextView>Auto Link>all (自動辨識)
android:textAppearance="?android:attr/textAppearanceLargeSmall" //設為小字,會依據解析度自動調整
GenyMotion Android模擬器
https://www.genymotion.com/
程式碼:
package com.example.bmi;
import android.os.Bundle;
- Dec 13 Sat 2014 12:01
Thread 執行緒
建立執行緒步驟:
第一種作法 :
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();
}
}
- Dec 13 Sat 2014 09:39
考古題
(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.
- Dec 12 Fri 2014 21:14
[Android] Picture Switcher
- Dec 12 Fri 2014 20:50
[Android] 第三堂
申請免費網站空間,靜態網頁+SQL: www.000webhost.com
我們的網站: http://coderspace.webatu.com/
未來package name就可以設成: com.webatu.coderspace.androidTest (package name)
xml name space: 這個名字=真正的本尊
Uniform Resource Identifier => 協定://資源持有單位/資源第一層分類/.../第n層分類/資源名稱
統一 資源 識別
URLocation
@ = 對系統說的話
@口 = 查詢
- Dec 08 Mon 2014 20:35
[Android] 程式開發實務
Android程式開發實務
第一堂課(2014.12.08) JJ Lin老師
Windows 環境設定
新增環境變數JAVA_HOME
新增環境變數CLASSPATH
編輯環境變數PATH
Eclipse 環境設定
使用老師的ADK懶人包,僅安裝需要的Android模擬器檔案
Android Virtual Device (AVD) 設定範例
練習在兩台虛擬機內傳簡訊、打電話。
後續建議用USB線連接實機,Eclipse 右上方新增DDMS面板
- Dec 06 Sat 2014 18:23
程式練習作業
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:
- Dec 06 Sat 2014 15:29
Java 例外處理 Exception Handling
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 解決問題
- Dec 06 Sat 2014 09:53
Hash, Collection, 泛型
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)
- Nov 15 Sat 2014 15:50
內部類別
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 指令
}
- Nov 15 Sat 2014 09:50
Java原廠教材
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){
- Nov 10 Mon 2014 19:15
[Java Web] 環境設定 WEB原理簡介
Eric老師推薦安裝MyEclipse+TomCat7+HTTP Watch來開發Java Web Project
網頁Server運作原理:
本機首先查詢本機host檔案有無查詢的網址,如果有便直接帶到網站。如果沒有,會對網路DNS Server發出Header訊息(檔頭),DNS向該網站確認是否存在,確認之後帶到該網站。
網站會在向後端資料庫詢問是否有index.jsp OR index.html等網頁(記載在web.xml內)
JSP網頁主要就是在寫上圖Yahoo網站到SQL的這一部分。
- Nov 08 Sat 2014 11:54
字串method範例
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