JAVA GUI Introduction I GUI java swingpackage Graphic

  • Slides: 17
Download presentation
JAVA 程式設計與資料結構 第八章 GUI Introduction I

JAVA 程式設計與資料結構 第八章 GUI Introduction I

GUI ¬使用java. swing的package來設計視窗介 面,我們稱之為Graphic User Interface(GUI)。 ¬在設計GUI的時候,需要import javax. swing. *; 才可以編譯。

GUI ¬使用java. swing的package來設計視窗介 面,我們稱之為Graphic User Interface(GUI)。 ¬在設計GUI的時候,需要import javax. swing. *; 才可以編譯。

GUI物件 1. 2. 3. 4. 5. 6. Top-Level Containers : Applet, Dialog, Frame. General-Purpose

GUI物件 1. 2. 3. 4. 5. 6. Top-Level Containers : Applet, Dialog, Frame. General-Purpose Containers : Panel, Scroll Pane, Split pane, Tabbed pane, Tool bar. Special-Purpose Containers : Internal frame, Layered pane, Root pane. Basic Controls : Buttons, Combo box, List, Menu, Slider, Spinner, Text field. Uneditable Information Displays : Label, Progress bar, Tool tip. Interactive Displays of Highly Formatted Information : Color chooser, File chooser, Table, Text, Tree.

JFrame ¬ JFrame屬於GUI中的 上層Container(Top. Level Containers), 所有的GUI物件都得 有一個Top-Level Container來承裝,所 以除了Applet跟 Dialog之外,我們只 可以用JFrame來承裝 其他GUI物件。

JFrame ¬ JFrame屬於GUI中的 上層Container(Top. Level Containers), 所有的GUI物件都得 有一個Top-Level Container來承裝,所 以除了Applet跟 Dialog之外,我們只 可以用JFrame來承裝 其他GUI物件。

JFrame set. Location() set. Title() get. Content. Pane() set. Size()

JFrame set. Location() set. Title() get. Content. Pane() set. Size()

JButtons ¬JButton便是按鈕,是屬於Basic Controls 中的一種。Button可用來激發事件。 需加入Event Listener 方 能激發 配置在 JFrame之中

JButtons ¬JButton便是按鈕,是屬於Basic Controls 中的一種。Button可用來激發事件。 需加入Event Listener 方 能激發 配置在 JFrame之中

JButtons Event Listener 使用add. Action. Listener() 方法來將此物件加諸在 JButton上,如 ok. add. Action. Listener(new Button_Action. Listener());

JButtons Event Listener 使用add. Action. Listener() 方法來將此物件加諸在 JButton上,如 ok. add. Action. Listener(new Button_Action. Listener());

建立有圖形的Label ¬使用Image. Icon物件來建立。 ¬先建立Image. Icon物件: – Image. Icon icon = new Image. Icon("next. Arrow.

建立有圖形的Label ¬使用Image. Icon物件來建立。 ¬先建立Image. Icon物件: – Image. Icon icon = new Image. Icon("next. Arrow. gif", "To Next Page"); ¬接下來宣告JLabel物件: – label = new JLabel("Next Page", icon, JLabel. CENTER);

JText. Area ¬JText. Area剛好可以算是JText. Field的延伸, JText. Field只有一行,而JText. Area則可以 有許多行(multiple lines)。 ¬其設定及建立方式與JText. Field類似。

JText. Area ¬JText. Area剛好可以算是JText. Field的延伸, JText. Field只有一行,而JText. Area則可以 有許多行(multiple lines)。 ¬其設定及建立方式與JText. Field類似。

Menus JMenu. Item JMenu. Bar

Menus JMenu. Item JMenu. Bar