import javax swing import java awt public class
![](https://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-1.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-2.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-3.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-4.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-5.jpg)
![import javax. swing. *; //引用套件 import java. awt. *; public class Border. Layout. EX import javax. swing. *; //引用套件 import java. awt. *; public class Border. Layout. EX](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-6.jpg)
import javax. swing. *; //引用套件 import java. awt. *; public class Border. Layout. EX extends JFrame { 範例 2 -1 Boder. Layout Border. Layout. EX() { Container cp = get. Content. Pane(); //取得內容面版 cp. set. Layout(new Border. Layout(10, 10)); //建立各區域水平、垂直間距為 10的Border. Layout物件 //將各按鈕控制項,加入版面的指定位置 cp. add(new JButton("EAST"), Border. Layout. EAST); cp. add(new JButton("WEST"), Border. Layout. WEST); cp. add(new JButton("SOUTH"), Border. Layout. SOUTH); cp. add(new JButton("NORTH"), Border. Layout. NORTH); cp. add(new JButton("CENTER")); //將元件加入中間區域, //相當於cp. add(new JButton("CENTER", Border. Layout. CENTER)); set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); pack(); set. Visible(true); } public static void main(String args[]) { new Border. Layout. EX(); } }
![add()方法的規格如下: public Component add(Component comp) public Component add(Component comp, int index) 回傳值:完成加入的元件,型別為Component。 使用Border. Layout時,置入各區域之元件的大小,並不是設定的大小,而將依照 add()方法的規格如下: public Component add(Component comp) public Component add(Component comp, int index) 回傳值:完成加入的元件,型別為Component。 使用Border. Layout時,置入各區域之元件的大小,並不是設定的大小,而將依照](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-7.jpg)
add()方法的規格如下: public Component add(Component comp) public Component add(Component comp, int index) 回傳值:完成加入的元件,型別為Component。 使用Border. Layout時,置入各區域之元件的大小,並不是設定的大小,而將依照 Borader. Layout的規則控制,說明如下表。 Flow. Layout佈局管理員 Flow. Layout類別的繼承架構如圖所示。
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-8.jpg)
![flow. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Flow. flow. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Flow.](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-9.jpg)
flow. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Flow. Layout. EX extends JFrame { Flow. Layout. EX() { Container cp = get. Content. Pane(); //取得內容面版 cp. set. Layout(new Flow. Layout(Flow. Layout. RIGHT)); //設定使用版面配置將運用靠右對齊的Flow. Layout物件 for(int i=1; i<=5; i++) cp. add(new JButton("按鈕 " + i)); //將按鈕控制項加入面版 set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); set. Size(300, 150); //設定視窗的寬度為 300, 高度為 150 set. Visible(true); } public static void main(String args[]) { new Flow. Layout. EX(); } }
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-10.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-11.jpg)
![Grid. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Grid. Grid. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Grid.](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-12.jpg)
Grid. Layout import javax. swing. *; //引用套件 import java. awt. *; public class Grid. Layout. EX extends JFrame { Grid. Layout. EX() { Container cp = get. Content. Pane(); //取得內容面版 cp. set. Layout(new Grid. Layout(3, 4, 10)); //指定版面運用 3列 4行的格狀佈局管理員, 水平與垂直間距分別為 10 for(int i=1; i<=7; i++) cp. add(new JButton("Button_" + i)); //將7個按鈕元件加入版面 set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); set. Size(300, 150); set. Visible(true); } public static void main(String args[]) { new Grid. Layout. EX(); } }
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-13.jpg)
![import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 public class Grid. Bag. import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 public class Grid. Bag.](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-14.jpg)
import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 public class Grid. Bag. Layout. EX 01 extends JFrame { Grid. Bag. Layout Ex 2 -4 Grid. Bag. Layout. EX 01() { Container cp = get. Content. Pane(); //取得版面 cp. set. Layout(new Grid. Bag. Layout()); //設定使用Grid. Bag. Layout版面配置 JButton btn. One = new JButton("Button One"); btn. One. set. Preferred. Size(new Dimension(120, 40)); //設定元件的喜好大小 cp. add(btn. One); //將按鈕加到版面 cp. add(new JButton("2")); cp. add(new JButton("Button Three")); cp. add(new JButton("Button 4")); set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); //設定關閉視窗時,將結束應用程式 set. Size(400, 80); //調整視窗大小 set. Visible(true); //顯示視窗 } public static void main(String args[]) { new Grid. Bag. Layout. EX 01(); //宣告建立視窗畫面的frame物件 } }
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-15.jpg)
![import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 Grid. Bag. Layout Ex import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 Grid. Bag. Layout Ex](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-16.jpg)
import javax. swing. *; //引用Swing套件 import java. awt. *; //引用AWT套件 Grid. Bag. Layout Ex 2 -5 public class Grid. Bag. Layout. EX 02 extends JFrame { Grid. Bag. Layout. EX 02() { Container cp = get. Content. Pane(); //取得版面 cp. set. Layout(new Grid. Bag. Layout()); //設定使用Grid. Bag. Layout版面配置 Grid. Bag. Constraints gbc = new Grid. Bag. Constraints(); //宣告控制元件版面配置的Grid. Bag. Constraints物件 gbc. insets = new Insets(5, 5, 5, 5); //設定元件與四周元件的距離 /***加入第一列的元件***/ gbc. ipadx = gbc. ipady = 15; //設定元件內文字與四周邊界的間距均為 15 gbc. gridx = 0; gbc. gridy = 0; //設定元件的行列位置 cp. add(new JButton("Button One"), gbc); //將按鈕加到版面 gbc. gridx = 1; gbc. gridy = 0; //設定元件的行列位置 cp. add(new JButton("2"), gbc); /***加入第二列的元件***/ gbc. ipadx = gbc. ipady = 0; //設定元件內文字與四周邊界的間距均為 0
![gbc. gridx = 0; gbc. gridy = 1; // 設定元件的行列位置 cp. add(new JButton("Button Three"), gbc. gridx = 0; gbc. gridy = 1; // 設定元件的行列位置 cp. add(new JButton("Button Three"),](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-17.jpg)
gbc. gridx = 0; gbc. gridy = 1; // 設定元件的行列位置 cp. add(new JButton("Button Three"), gbc); gbc. gridx = 1; gbc. gridy = 1; //設定元件的行列位置 cp. add(new JButton("Button 4"), gbc); /***加入第三列的元件***/ gbc. insets = new Insets(0, 0, 0, 0); //設定元件與四周元件的距離 gbc. gridx = 0; gbc. gridy = 2; //設定元件的行列位置 cp. add(new JButton("Button 5"), gbc); //將按鈕加到版面 gbc. gridx = 1; gbc. gridy = 2; //設定元件的行列位置 cp. add(new JButton("Button 6"), gbc); /***加入第四列的元件***/ gbc. gridx = 0; gbc. gridy = 3; //設定元件的行列位置 cp. add(new JButton("Button 7"), gbc); gbc. gridx = 1; gbc. gridy = 3; //設定元件的行列位置 cp. add(new JButton("Button 8"), gbc); set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); //設定關閉視窗時,將結束應用程式 pack(); //調整視窗大小 set. Visible(true); //顯示視窗 } public static void main(String args[]) { new Grid. Bag. Layout. EX 02(); //宣告建立視窗畫面的frame物件 } }
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-18.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-19.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-20.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-21.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-22.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-23.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-24.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-25.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-26.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-27.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-28.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-29.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-30.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-31.jpg)
![Spring. Layout佈局管理員 Spring. Layout的配置方式 Spring. Layout類別的繼承架構如下所示。 下表將分別說明Spring. Layout、Spring. Layout. Constraints與Spring的功能: Spring類別的繼承架構如圖所示。 Spring. Layout佈局管理員 Spring. Layout的配置方式 Spring. Layout類別的繼承架構如下所示。 下表將分別說明Spring. Layout、Spring. Layout. Constraints與Spring的功能: Spring類別的繼承架構如圖所示。](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-32.jpg)
Spring. Layout佈局管理員 Spring. Layout的配置方式 Spring. Layout類別的繼承架構如下所示。 下表將分別說明Spring. Layout、Spring. Layout. Constraints與Spring的功能: Spring類別的繼承架構如圖所示。
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-33.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-34.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-35.jpg)
![Spring. Layout. Constraints類別的建構子與常用方法 下表將說明Spring. Layout. Constraints類別的建構子與常用方法。 Spring. Layout. Constraints類別的建構子與常用方法 下表將說明Spring. Layout. Constraints類別的建構子與常用方法。](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-36.jpg)
Spring. Layout. Constraints類別的建構子與常用方法 下表將說明Spring. Layout. Constraints類別的建構子與常用方法。
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-37.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-38.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-39.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-40.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-41.jpg)
![以下為make. Grid()方法與make. Compact. Grid()方法的規格: public static void make. Grid( Container parent, int rows, int 以下為make. Grid()方法與make. Compact. Grid()方法的規格: public static void make. Grid( Container parent, int rows, int](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-42.jpg)
以下為make. Grid()方法與make. Compact. Grid()方法的規格: public static void make. Grid( Container parent, int rows, int cols, int initial. X, int initial. Y, int x. Pad, int y. Pad)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-43.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-44.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-45.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-46.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-47.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-48.jpg)
![File. Input. Stream類別 Input. Stream與Output. Steram類別可處理的資料 File. Input. Stream類別可處理 純文字檔 二進位檔(binary file) 以「位元組」為主的輸入 作 File. Input. Stream類別 Input. Stream與Output. Steram類別可處理的資料 File. Input. Stream類別可處理 純文字檔 二進位檔(binary file) 以「位元組」為主的輸入 作](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-49.jpg)
File. Input. Stream類別 Input. Stream與Output. Steram類別可處理的資料 File. Input. Stream類別可處理 純文字檔 二進位檔(binary file) 以「位元組」為主的輸入 作 下表列出File. Input. Stream類別的建構元: 49
![File. Input. Stream類別的函數 下表列出File. Input. Stream類別的函數: 50 File. Input. Stream類別的函數 下表列出File. Input. Stream類別的函數: 50](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-50.jpg)
File. Input. Stream類別的函數 下表列出File. Input. Stream類別的函數: 50
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-51.jpg)
![使用File. Output. Straem類別 下表列出File. Output. Stream類別的建構元與常用函數: 52 使用File. Output. Straem類別 下表列出File. Output. Stream類別的建構元與常用函數: 52](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-52.jpg)
使用File. Output. Straem類別 下表列出File. Output. Stream類別的建構元與常用函數: 52
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-53.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-54.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-55.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-56.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-57.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-58.jpg)
![](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-59.jpg)
![Scanner 檔案輸入 (1) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner; Scanner 檔案輸入 (1) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner;](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-60.jpg)
Scanner 檔案輸入 (1) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner; public class Fs { public static void main(String args[]) throws IOException { File. Reader fr=new File. Reader("fnum. txt"); // 建立物件fr int age[]=new int [10]; Scanner scn=new Scanner(fr); System. out. println("The ages are = "); for (int i=0; i<10; i++){ age[i]=scn. next. Int(); // 輸入整數 if (i!=9) System. out. print(age[i]+", "); else System. out. println(age[i]+" "); } fr. close(); } }
![Scanner 檔案輸入 (2) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner; Scanner 檔案輸入 (2) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner;](http://slidetodoc.com/presentation_image_h/fb89c1614980db744f1be00b87b81338/image-61.jpg)
Scanner 檔案輸入 (2) import java. io. *; // 載入java. io類別庫裡的所有類別 import java. util. Scanner; public class Fs 2 { public static void main(String args[]) throws IOException { int i=0; File. Reader fr=new File. Reader("fnum 2. txt"); // 建立物件fr int age[]=new int [10]; Scanner scn=new Scanner(fr); scn. use. Delimiter(", "); System. out. println("The ages are = "); while (scn. has. Next()){ age[i]=scn. next. Int(); //輸入整數 System. out. print(age[i]+" "); i++; } fr. close(); } }
- Slides: 61