2011-06-02

第十五週

首先,建立一個專案(Project)名為 Change

在Change→com.android.change→Change.java的地方

貼上
package com.android.change;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Change extends Activity {
    
private EditText ed1, ed2;
private Button btn1;
private TextView tv1;
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);
        
ed1 = (EditText)Change.this.findViewById(R.id.editText1);  // 匯率
ed2 = (EditText)Change.this.findViewById(R.id.editText2);  // 台幣
btn1 = (Button)Change.this.findViewById(R.id.button1);
tv1 = (TextView)Change.this.findViewById(R.id.textView3);
    
      
ed1.setText("33.5");
ed2.setText("10000");
      
Double nu1= Double.valueOf(ed1.getText().toString());
Double nu2= Double.valueOf(ed2.getText().toString());
String sum=String.valueOf(nu2/nu1);
tv1.setText(sum);
btn1.setOnClickListener(new Button.OnClickListener()
{
      
public void onClick(View arg0)
{
          btn1.setWidth(70);
            
            
// 按鈕事件,處理數學換算的語法
//NumberFormat nf = NumberFormat.getInstance();
 //nf.setMaximumFractionDigits( 2 );
          
 //double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
          
//tv1.setText( Try3.this.getResources().getString(R.string.str3) + ":" + nf.format(d) );
        
 }
 });
         
    }
}

在Change→layout→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:text="@string/str2"
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </TextView>
       
    <EditText
     android:layout_height="wrap_content"
     android:id="@+id/editText1"
     android:text=""
     android:layout_width="match_parent">
     </EditText>
     
    <TextView
    android:text="@string/str3"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    android:layout_width="wrap_content">
    </TextView>
    
    <EditText
    android:layout_height="wrap_content"
    android:id="@+id/editText2"
    android:text=""
    android:layout_width="match_parent">
    </EditText>
    <Button android:text="計算台幣兌換美金" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    
    <TextView
    android:text="@string/str_btn1"
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </TextView>
    
</LinearLayout>


在Change→values→main.xml的地方

貼上
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">Hello World, EX203!</string>
  <string name="app_name">匯率換算</string>
  
  <string name="str1">匯率換算</string>
  <string name="str2">匯率</string>
  <string name="str3">臺幣</string>
  
  <string name="str_btn1">可兌換美金</string>
  <string name="String00">匯率</string>
</resources>


完成!!

2011-05-19

第十三週

首先,先去下載   eclipse 
打開之後解壓縮(是一個可以帶著走的程式)
打開eclipse之後
執行  Hello World  (按照右方的指示)
如果成功就代表eclipse可以執行
接著我們要安裝Android

按Help->Install New Softare

Add 
Name :ADT
電腦找到之後  全選
安裝



↑安裝超久的!!

安裝之後按Restart
之後進去按Preference選android
location 打D:\java-s\android-sdk-windows
會發現沒有裝SDK
只好回去裝SDK(在android-sdk-windows資料夾裡)

虹虹碎碎念:   安裝要花費好多時間啊> <


安裝成功後
按一下這個按紐

New→創建test→start
建立一個新的project
輸入範例中的BMI
如果target不能按就重開eclipse吧

成功囉~





第十二堂課

一開始,先去老師的網站

下載檔案


下載檔案



                              000006.dcm



接下來解壓縮ij129.zip 
得到image J
會發現裡面有一個ij.jar
複製貼到D:\Java\jdk1.6.0_24\jre\lib\ext

然後編輯run2.bat 
執行
set CLASSPATH=ij.jar;.
javac -deprecation DicomViewer.java
java DicomViewer 000006.dcm
得到一個醫學影像


加入
import ij.process.*;
ImageProcessor ip = null;
img = imp.getImage();
ip = new ByteProcessor(img);
ip.noise(20);

就可以成功地加入雜訊囉~

2011-05-05

第十一堂課

先去下載上禮拜的時鐘程式

Create a Timer object

進行修改
import javax.swing.Timer;
import java.awt.event.*;
import java.util.*;
import java.awt.*;//加入要用的套件
import javax.swing.*;//加入要用的套件

public class TimerDemo extends JFrame  implements ActionListener {
static JTextField tbx1=new JTextField(10);//加入文字方塊  Timer t = new Timer(1000,this);
  TimerDemo() {
    t.start();
    }

  public static void main(String args[]) {
    TimerDemo td = new TimerDemo();

GridLayout grid33= new GridLayout(3,3);//加入Layout,應該用什麼都可
JPanel p1 = new JPanel(grid33); //加入Panel
p1.add(tbx1);//在Panel中加入tbx1
td.add(p1);//在frame(td)中加入Panel
td.setLayout(grid33);//設定td的Layout
td.setVisible(true);//讓td看的見
td.setSize(450,450);//設定td大小

    // create a dummy frame to keep the JVM running
    //  (for demonstation purpose)
    java.awt.Frame dummy = new java.awt.Frame();
    dummy.setVisible(true);
    }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == t) {
    //  System.out.println
       // ("Being ticked " + Calendar.getInstance().getTime());

tbx1.setText("YA " + Calendar.getInstance().getTime());
//讀取文字方塊內的物件,前片加個字串,java會把後面的也當成字串顯示      }
    }
}

extends JFrame 繼承



一開始,先去ImageJ Tutorial下載檔案

  • ImageJ tutorial (PDF)


  • Tutorial sample plugin files (ZIP)



  • 打開   ip-demo2  把上禮拜下載的染色體圖放進這個資料夾裡
    更改名稱Chromosomescouple
    在重開一次網頁,就可以看到染色體圖了
    如要再編譯一次IPDemo.java
    必須把ij.jar套件移到
    D:\Java\jdk1.6.0_24\jre\lib\ext裡才可以執行
    打開index.html的程式檔
    可以看到程式碼並修改寬高

     如果要不再網頁上開啟此檔案的時候
    就比需使用appletviewer.exe  去執行 index.html
    (此時java是行不通的)

    2011-04-29

    第十堂課

    一開始,先去  http://ccckmit.wikidot.com/ja:encapsulation  複製封裝的程式碼,藉此了解何謂是封裝
    

    打開文件檔,存成java的形式↓




    然後把class Person1剪下,存成另一個檔案↓


    修改一下

    在Object1加入 
    Person1 p3 = new Person1();
    p3.checkWeight();

    在Person1中加入
        Person1() 
          {      name   = "宜靜";
                      weight = 42;         }

    這樣子程式碼找不到條件時就會在
     Person1() 中找


    結果↓


    接著去老師的Blogger複製程式碼

    // with event
    //Swing, JButton類別 有ActionListener
    //Swing, JButton類別
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SwingEightPuzzleEvent extends JFrame implements ActionListener
    {
    //static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
    //static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
    static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
    static JButton buttons[]=new JButton[10];
    static JLabel labels[]=new JLabel [10];


    public SwingEightPuzzleEvent()
    {}//建構子

    public static void main(String args[])
    {
    SwingEightPuzzleEvent myfrm=new SwingEightPuzzleEvent();
    String numbers[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
    FlowLayout flow=new FlowLayout();
    GridLayout grid12= new GridLayout(1,2);
    GridLayout grid33= new GridLayout(3,3);
    myfrm.setLayout(grid12);
    myfrm.setSize(450,450);
    JPanel p1 = new JPanel(grid33); //實作 panel 1
    for (int i = 0; i < numbers.length; i++)
    {
    buttons[i] = new JButton(numbers[i]); // create buttons
    p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
    }


    myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
    JPanel p3 = new JPanel(grid33); //實作 panel 3
    for (int i = 0; i < numbers.length; i++)
    {
    labels[i] = new JLabel(); // create labels
    p3.add(labels[i], grid33); // 在 panel 1內加入按鈕陣列
    }
    myfrm.add(p3); // 在視窗myfrm 內加入 panel 3


    JPanel p2 = new JPanel(flow); //實作 panel 2
    JButton btn1=new JButton("JButton 1"); // 建立按鈕物件 btn1
    btn1.addActionListener(myfrm);
    p2.add(tbx1); // 在 panel 2內加入文字方塊
    p2.add(btn1); // 在 panel 2內加入按鈕


    myfrm.add(p2); // 在視窗myfrm 內加入 panel 2
    myfrm.setVisible(true);
    }


    public void actionPerformed(ActionEvent e)
    {
    String numbers[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
    //int rndno;
    //String stringValue;
    //stringValue=tbx1.getText();
    //int intValue = Integer.parseInt(stringValue);
    //System.out.println(intValue);
    //labels[intValue].setText(stringValue);


    /*
    for (int j = 0; j < 9; j++)
    {
    //rndno=(int) (Math.random()*9);
    //System.out.println(rndno);
    //numbers[i]=String.valueOf(rndno); 
    //buttons[i].setLabel(numbers[i]); 
    }
    */


    //tbx1.setText(numbers[0]);
    //buttons[rndno].setBackground(Color.blue);
    //labels[rndno].setText(numbers[0]);
    }
    }



    開始幫他瘦身囉~
    把一些可以移到建構子的程式移進去建構子

    public SwingEightPuzzleEvent()
    {}//建構子
    如果建構子跟class main 都會用到的程式就移到最上面去
    這樣就可以兩個都包含在內了

    整理過後的程式↓

    // with event
    //Swing, JButton類別 有ActionListener
    //Swing, JButton類別
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SwingEightPuzzleEvent extends JFrame implements ActionListener
    {
    //static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
    //static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
    static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
    static JButton buttons[]=new JButton[10];
    static JLabel  labels[]=new JLabel [10];
    static FlowLayout flow=new FlowLayout();
    static GridLayout grid33= new GridLayout(3,3);

    static JButton btn1=new JButton("JButton 1"); // 建立按鈕物件 btn1

    static  JPanel p1 = new JPanel(grid33); //實作  panel 1
    static JPanel p2 = new JPanel(flow); //實作  panel 2
    static JPanel p3 = new JPanel(grid33); //實作  panel 3

    static  String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};

    static GridLayout grid12= new GridLayout(1,2);

    public SwingEightPuzzleEvent()
    {


    for (int i = 0; i < numbers.length; i++)
    {
    labels[i] = new JLabel(); // create labels
    p3.add(labels[i], grid33); // 在 panel 1內加入按鈕陣列
    }

    for (int i = 0; i < numbers.length; i++)
    {
    buttons[i] = new JButton(numbers[i]); // create buttons
    p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
    }

    p2.add(tbx1); // 在 panel 2內加入文字方塊
    p2.add(btn1); // 在 panel 2內加入按鈕
    }

    public static void main(String args[])
    {
    SwingEightPuzzleEvent myfrm=new SwingEightPuzzleEvent();

    myfrm.setLayout(grid12);
    myfrm.setSize(450,450);

    myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
    myfrm.add(p3); // 在視窗myfrm 內加入 panel 3



    btn1.addActionListener(myfrm);


    myfrm.add(p2); // 在視窗myfrm 內加入 panel 2

    myfrm.setVisible(true);
    }




    今天的作業就是去http://www.rgagnon.com/javadetails/java-0144.html複製程式碼
    分別執行套件的運用
    就完成囉~






    2011-04-24

    第九堂課

    首先,先去老師的部落格複製程式碼


    // with event

    //Swing, JButton類別 有ActionListener
    //Swing, JButton類別
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SwingTestEvent extends JFrame implements ActionListener
    {
    //static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
    //static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
    static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
    static JButton buttons[]=new JButton[10];
    static JLabel  labels[]=new JLabel [10];
    public static void main(String args[])
    {
    SwingTestEvent myfrm=new SwingTestEvent();

    String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
    FlowLayout flow=new FlowLayout();
    GridLayout grid12= new GridLayout(1,2);
    GridLayout grid33= new GridLayout(3,3);
    myfrm.setLayout(grid12);
    myfrm.setSize(450,450);
    JPanel p1 = new JPanel(grid33); //實作  panel 1
    for (int i = 0; i < numbers.length; i++)
    {
    buttons[i] = new JButton(numbers[i]); // create buttons
    p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
    }

    myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
    JPanel p3 = new JPanel(grid33); //實作  panel 3
    for (int i = 0; i < numbers.length; i++)
    {
    labels[i] = new JLabel(); // create labels
    p3.add(labels[i], grid33); // 在 panel 1內加入按鈕陣列
    }
    myfrm.add(p3); // 在視窗myfrm 內加入 panel 3

    JPanel p2 = new JPanel(flow); //實作  panel 2
    JButton btn1=new JButton("JButton 1"); // 建立按鈕物件 btn1
    btn1.addActionListener(myfrm);
    p2.add(tbx1); // 在 panel 2內加入文字方塊
    p2.add(btn1); // 在 panel 2內加入按鈕

    myfrm.add(p2); // 在視窗myfrm 內加入 panel 2


    myfrm.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    String stringValue;
    stringValue=tbx1.getText();
    int intValue = Integer.parseInt(stringValue);
    System.out.println(intValue);
    buttons[intValue].setBackground(Color.blue);
    labels[intValue].setText(stringValue);

    }
    }



    進行修改

    /*String stringValue;

    stringValue=tbx1.getText();
    int intValue = Integer.parseInt(stringValue);
    System.out.println(intValue);
    buttons[intValue].setBackground(Color.blue);

    labels[intValue].setText(stringValue);*/

    加入
    String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};//九個抽屜
    int rndon=(int)(Math.random()*9);//產生9個亂數
    System.out.println( rndon);
    numbers[0]=String.valueOf(rndon);

    buttons[rndon].setBackground(Color.blue);//輸入哪個數字那個數字就會變藍色
    tbx1.setText(numbers[0]);
    labels[rndon].setText(numbers[0]);//改變標籤上的字

    在public void actionPerformed(ActionEvent e)裡



    如果要擷取三個抽屜裡的數字,我們就必須複製三次,以此類推
    ex:
    String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"}
    String Stringvalue;

    int rndon

     rndon=(int)(Math.random()*9);
    System.out.println( rndon);
    numbers[0]=String.valueOf(rndon);
    buttons[0].setLabel(numbers[0]);

     rndon=(int)(Math.random()*9);
    System.out.println( rndon);
    numbers[1]=String.valueOf(rndon);
    buttons[1].setLabel(numbers[1]);

    rndon=(int)(Math.random()*9);
    System.out.println( rndon);
    numbers[2]=String.valueOf(rndon);
    buttons[2].setLabel(numbers[2]);

    如果用for迴圈就可以不用如此麻煩了
    for (int i = 0; i < 9; i++)
    {
    rndon=(int)(Math.random()*9);
    System.out.println( rndon);
    numbers[i]=String.valueOf(rndon);
    buttons[i].setLabel(numbers[i]);
    }

    for{要執行的程式}

    今天我們要做的是產生5*5亂數
    (類似玩bingo遊戲用的)
    所以我們要幫數字換位子
    ex:
    0 1 2 3 4 5 6 7 8 
    產生亂數2
    擷取第2個抽屜裡的數字[2]換到最後一個
    變成
    0 1 8 3 4 5 6 7 2
    再產生亂數2
    擷取第二個抽屜裡面的數字[8]
    變成
    0 1 7 3 4 5 6 8 2
    換過的數字就不動了

    所以我們必須製造第三個位子給數字暫時坐著

    tmp就是暫時的位子

    加入
    String tmp;
    tmp=numbers[8];
    //tmp給第八個抽屜裡的數字坐
    numbers[8]=numbers[rndon];
    //random產生的第rndon個抽屜裡的數字坐到第八個抽屜
    numbers[rndon]=tmp;
    //tmp裡的抽屜再坐到rndon裡





    最後的程式碼↓
    // with event
    //Swing, JButton類別 有ActionListener
    //Swing, JButton類別
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.*;
    public class SwingTestEvent extends JFrame implements ActionListener
    {
    //static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
    //static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
    static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
    static JButton buttons[]=new JButton[25];
    static JLabel  labels[]=new JLabel [25];
    public static void main(String args[])
    {
    SwingTestEvent myfrm=new SwingTestEvent();

    String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
    FlowLayout flow=new FlowLayout();
    GridLayout grid12= new GridLayout(1,2);
    GridLayout grid33= new GridLayout(5,5);
    myfrm.setLayout(grid12);
    myfrm.setSize(450,450);
    JPanel p1 = new JPanel(grid33); //實作  panel 1
    for (int i = 0; i < numbers.length; i++)
    {
    buttons[i] = new JButton(numbers[i]); // create buttons
    p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
    }

    myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
    JPanel p3 = new JPanel(grid33); //實作  panel 3
    for (int i = 0; i < numbers.length; i++)
    {
    labels[i] = new JLabel(); // create labels
    p3.add(labels[i], grid33); // 在 panel 1內加入按鈕陣列

    }
    myfrm.add(p3); // 在視窗myfrm 內加入 panel 3

    JPanel p2 = new JPanel(flow); //實作  panel 2
    JButton btn1=new JButton("JButton 1"); // 建立按鈕物件 btn1
    btn1.addActionListener(myfrm);
    p2.add(tbx1); // 在 panel 2內加入文字方塊
    p2.add(btn1); // 在 panel 2內加入按鈕

    myfrm.add(p2); // 在視窗myfrm 內加入 panel 2


    myfrm.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    //String stringValue;
    //stringValue=tbx1.getText();
    //int intValue = Integer.parseInt(stringValue);
    //System.out.println(intValue);
    //buttons[intValue].setBackground(Color.blue);
    //labels[intValue].setText(stringValue);
    String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
    String Stringvalue;
    int rndon;

    String tmp;
    for (int i = 0; i < 25; i++)
    {
    int j=24-i;
    rndon=(int)(Math.random()*(j+1));
    System.out.println( rndon);
    tmp=numbers[j];
    numbers[j]=numbers[rndon];
    numbers[rndon]=tmp;
    }
    for (int i = 0; i < 25; i++)
    {
    System.out.println( numbers[i]);
    buttons[i].setLabel(numbers[i]);
    }

    //buttons[rndon].setBackground(Color.blue);
    //tbx1.setText(numbers[0]);
    //labels[rndon].setText(numbers[0]);

    }
    }





    ※ 記得要改
    static JButton buttons[]=new JButton[25];
    static JLabel  labels[]=new JLabel [25];
    這樣才有25個空格可以裝得下

    ※ String numbers[]  = {"0", "1", "2", "3", "4", "5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
    25個抽屜

    ※ GridLayout grid33= new GridLayout(5,5);用5*5的
    GridLayout

    ※ 加入import java.lang.*setLabel才有辦法執行

    ※ j=24-i的原因是產生的亂數不能一直介在1~25之間,要逐一減少

    ※ (Math.random()*(j+1))的原因是i<25

    ※ 寫出for (int i = 0; i < 25; i++)
    {
    System.out.println( numbers[i]);
    buttons[i].setLabel(numbers[i]);
    }
    的原因是要知道它變化的情況,
    不然它會直接在系統裡面變化,我們看不到

    結果圖↓



    進階!!
    就是要在60之內去25個數字放進去空格裡
    為了省去要打到60個麻煩
    加入
    String numbers[]=new String[61];
    for (int i = 0; i <60; i++)
    {
    numbers[i]=String.valueOf(i);
    }


    Button數跟Label以及GridLayout都維持不變
    加入

    String tmp;
    for (int i = 0; i < 61 ; i++)
    {
    int j= 60 -i;
    rndon=(int)(Math.random()*(j+1));
    System.out.println( rndon);
    tmp=numbers[j];
    numbers[j]=numbers[rndon];
    numbers[rndon]=tmp;
    }
    for (int i = 0; i <25; i++)
    {
    System.out.println( numbers[i]);
    buttons[i].setLabel(numbers[i]);
    }


    完成!!



    程式碼如下

    // with event
    //Swing, JButton類別 有ActionListener
    //Swing, JButton類別
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.*;
    public class SwingTestEvent extends JFrame implements ActionListener
    {
    //static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
    //static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
    static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
    static JButton buttons[]=new JButton[25];
    static JLabel  labels[]=new JLabel [25];
    public static void main(String args[])
    {
    SwingTestEvent myfrm=new SwingTestEvent();

    //String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
    String numbers[]=new String[61];
    for (int i = 0; i <60; i++)
    {
    numbers[i]=String.valueOf(i);
    }
    FlowLayout flow=new FlowLayout();
    GridLayout grid12= new GridLayout(1,2);
    GridLayout grid33= new GridLayout(5,5);
    myfrm.setLayout(grid12);
    myfrm.setSize(450,450);
    JPanel p1 = new JPanel(grid33); //實作  panel 1
    for (int i = 0; i < 25; i++)
    {
    buttons[i] = new JButton(numbers[i]); // create buttons
    p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
    }

    myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
    JPanel p3 = new JPanel(grid33); //實作  panel 3
    for (int i = 0; i <25; i++)
    {
    labels[i] = new JLabel(); // create labels
    p3.add(labels[i], grid33); // 在 panel 1內加入按鈕陣列
    }
    myfrm.add(p3); // 在視窗myfrm 內加入 panel 3

    JPanel p2 = new JPanel(flow); //實作  panel 2
    JButton btn1=new JButton("JButton 1"); // 建立按鈕物件 btn1
    btn1.addActionListener(myfrm);
    p2.add(tbx1); // 在 panel 2內加入文字方塊
    p2.add(btn1); // 在 panel 2內加入按鈕

    myfrm.add(p2); // 在視窗myfrm 內加入 panel 2


    myfrm.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    //String stringValue;
    //stringValue=tbx1.getText();
    //int intValue = Integer.parseInt(stringValue);
    //System.out.println(intValue);
    //buttons[intValue].setBackground(Color.blue);
    //labels[intValue].setText(stringValue);
    //String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
    String numbers[]=new String[61];
    for (int i = 0; i <60; i++)
    {
    numbers[i]=String.valueOf(i);
    }
    String Stringvalue;
    int rndon;
    /*for (int i = 0; i < 9; i++)
    {
    rndon=(int)(Math.random()*9);
    System.out.println( rndon);
    numbers[i]=String.valueOf(rndon);
    buttons[i].setLabel(numbers[i]);
    }
    */

    String tmp;
    for (int i = 0; i < 61 ; i++)
    {
    int j= 60 -i;
    rndon=(int)(Math.random()*(j+1));
    System.out.println( rndon);
    tmp=numbers[j];
    numbers[j]=numbers[rndon];
    numbers[rndon]=tmp;
    }
    for (int i = 0; i <25; i++)
    {
    System.out.println( numbers[i]);
    buttons[i].setLabel(numbers[i]);
    }

    //buttons[rndon].setBackground(Color.blue);
    //tbx1.setText(numbers[0]);
    //labels[rndon].setText(numbers[0]);

    }
    }