2011年6月10日 星期五

期末作業

建立選單(Menu)

 在這個網站找到建立選單的方法

按下選單後
按下說明

出現說明


-----------------------------------------------------------------

匯率換算器加強版

加入可選擇幣值

選擇會出現提示

支援8種不同國家幣值


-------------------------------------------------------------------------------------------------------------
NewOne.java
-----------------------
package edu.fcu.wang;

import java.text.NumberFormat;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class NewOne extends Activity {
 private EditText ed1, ed2;
 private Button btn1;
 private TextView tv1;
 private Spinner sp1;
 public static final String MY_PREFS = "mSharedPreferences01";
    /** Called when the activity is first created. */
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sp1 = (Spinner)NewOne.this.findViewById(R.id.spinner1);
        ed1 = (EditText)NewOne.this.findViewById(R.id.editText1);  // 匯率
        ed2 = (EditText)NewOne.this.findViewById(R.id.editText2);  // 台幣
        btn1 = (Button)NewOne.this.findViewById(R.id.button1);
        tv1 = (TextView)NewOne.this.findViewById(R.id.textView4);
        ed1.setText("28.4");
        ed2.setText("10000");
        
        btn1.setOnClickListener(new Button.OnClickListener()
        {
          @Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 按鈕事件,處理數學換算的語法
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits( 2 );
            
            double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
            
            tv1.setText( NewOne.this.getResources().getString(R.string.str4) + ":" + nf.format(d));
}
        });
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"美金","英鎊","日幣","港幣","韓元","泰銖","印尼盾","歐元"});
      //設定下拉選單的樣式
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp1.setAdapter(adapter);
      //設定項目被選取之後的動作
        sp1.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
            public void onItemSelected(AdapterView adapterView, View view, int position, long id){
            Toast.makeText(NewOne.this, "您選擇"+adapterView.getSelectedItem().toString(), Toast.LENGTH_LONG).show();
           
            int pos = sp1.getSelectedItemPosition();
                try
            {
                    if (pos==0)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("28.58");
                    }
                  
                    if (pos==1)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("45.51");
                    }    
                    if (pos==2)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("0.35110");
                    }    
                    if (pos==3)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("3.57600");
                    }    
                    if (pos==4)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("0.02487");
                    }    
                    if (pos==5)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("0.83610");
                    }    
                    if (pos==6)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("0.00296");
                    }    
                    if (pos==7)
                    {
                      // TODO Auto-generated method stub
                      ed1.setText("40.23000");
                    }    
                  }
                  catch(Exception err)
                      {
                        
                      
                      }
                  
            }
            public void onNothingSelected(AdapterView arg0) {
                Toast.makeText(NewOne.this, "您沒有選擇任何項目", Toast.LENGTH_LONG).show();
            }
  
        });
      }/*End: onCreate()*/

      @Override
      protected void onResume()
      {
        // TODO Auto-generated method stub
        
        SharedPreferences mySharedPreferences = getSharedPreferences(MY_PREFS, Activity.MODE_PRIVATE);
        // 第二個參數為 假若 "rate" 不存在,程式為第一次執行的話,要以什麼值取代
        String previousInputRate = mySharedPreferences.getString("rate", "");
        ed1.setText(previousInputRate);
        super.onResume();
      }

      public void onItemSelected()
      {
      
          }
                  
        
       
      
      protected void onStop()
      {
        // TODO Auto-generated method stub
        SharedPreferences mySharedPreferences = getSharedPreferences(MY_PREFS, Activity.MODE_PRIVATE);
        SharedPreferences.Editor ed = mySharedPreferences.edit();
        ed.putString("rate", ed1.getText().toString() );
        ed.commit();
        
        super.onStop();
    }
}


-------------------------------------------------------------------------------------------------------------
main.xml
---------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  android:id="@+id/textView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/str1"/>

<EditText android:id="@+id/editText1" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:text="">
</EditText>

<TextView android:id="@+id/textView2" 
android:layout_height="wrap_content" 
android:text="@string/str2" 
android:layout_width="match_parent">
</TextView>

<EditText android:id="@+id/editText2" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:text="">
</EditText>
<TextView android:text="@string/str3" android:id="@+id/textView3" android:layout_height="wrap_content" android:layout_width="match_parent"></TextView>
<Spinner android:id="@+id/spinner1" android:layout_height="wrap_content" android:layout_width="match_parent"></Spinner>

<Button android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:id="@+id/button1" 
android:text="@string/str_btn1">
</Button>
<TextView android:id="@+id/textView4" android:text="@string/str4" android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
</LinearLayout>

2011年3月25日 星期五

第六周




設定一堆按鈕
 設定TextFlied
作7個TextFlied再把數帶進去
開獎!!!!!

 程式碼part1

 程式碼part2
String nb1 = Integer.toString(al); //數字轉字串
tfd1.setText(nb1); //把數字帶入Text

2011年3月18日 星期五

2011年2月18日 星期五

遇到困難

我照著網站步驟做,出現了
'javac' is not recognized as an internal or external command, operable program or batch file 的訊息

在網站我發現
If you encounter problems with the instructions in this step, consult the Common Problems (and Their Solutions).
剛好在裡面找到了我的問題
裡面寫到
If you receive this error, Windows cannot find the compiler (javac).
Here's one way to tell Windows where to find javac. Suppose you installed the JDK in C:\jdk6. At the prompt you would type the following command and press Enter: C:\jdk6\bin\javac HelloWorldApp.java If you choose this option, you'll have to precede your javac and java commands with C:\jdk6\bin\ each time you compile or run a program. To avoid this extra typing, consult the section in the JDK 6 installation instructions.

在阿莫的網站發現了找到程式路徑的方法
但是學校電腦權限限制實在太多
讓我用了許久
由於C碟權限太多於是我複製到D碟
再照著解決步驟把記事本複製到bin資料夾就解決了

2011年2月17日 星期四

物件導向程式設計_JAVA 第一週

一.
1.為何why要選修這門課?(動機)
因為一直都對電腦方面有興趣
也想多學習程式語言
自己在系上學程也是選修"資通安全學程"
所以才選修這門課
2.希望從這門課獲得那些知識?(目標)
首先想知道JAVA可以利用在哪些方面
接著利用JAVA實作一些程式
可以滿足自己的興趣
也希望對未來畢業之後有幫助
3.我要如何修習這一門課?(態度與方法)
who, when, where 
最基本的當然是每個禮拜準時到課
上課認真學習~
課餘時間可以利用上課所學自己去操作
試著做出課堂上所沒做過的程式

二.
回答問題: 請問您畢業後,如果找不到工作,您會花錢去上 "Java程式設計實力精修班" 課程嗎? 為甚麼?請您說明原因,100個字以上。
 
事實上,如果我沒修過這堂課的話,我或許會去上,因為本身自己就對這方面有興趣了,畢業後若又沒方向的話,能增強自己所學當然是好的,在要升三年級的時候自己也有嘗試去電腦補習班補習,但後來因課業與社團繁忙,就沒在繼續學了,但畢業後就不一樣了,若真的要為自己找一條路的話,當然是找自己最有興趣的路了!!