Microsoft PowerPoint ppt

Similar documents
Microsoft PowerPoint - course8.ppt

Chapter 9: Objects and Classes

Swing-02.pdf


PowerPoint 簡報

Chapter 9: Objects and Classes

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

Chapter 9: Objects and Classes

java2d-4.PDF

JavaIO.PDF

基于CDIO一体化理念的课程教学大纲设计

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

2 Java 语 言 程 序 设 计 教 程 简 单 性 Java 语 言 的 语 法 与 C 语 言 和 C++ 语 言 很 接 近, 使 得 大 多 数 程 序 员 很 容 易 学 习 和 使 用 Java 另 一 方 面,Java 丢 弃 了 C++ 中 很 少 使 用 的 很 难

Microsoft PowerPoint - ch02

Chapter 9: Objects and Classes

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

D C 93 2

ebook111-4

ebook 86-15

p.2 1 <HTML> 2 3 <HEAD> 4 <TITLE> </TITLE> 5 </HEAD> 6 7 <BODY> 8 <H3><B> </B></H3> 9 <H4><I> </I></H4> 10 </BODY> </HTML> 1. HTML 1. 2.

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

E3. 最 大 公 因 數 問 題 描 述 : 寫 一 程 式 求 兩 數 之 最 大 公 因 數 利 用 TextField 元 件 輸 入 正 整 數 M, N (1 N M 9999), 按 下 compute 按 鈕 後 計 算 正 整 數 M, N 的 最 大 公 因 數, 並 顯 示 於

Microsoft Word - 01.DOC

chp6.ppt

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

javaexample-02.pdf

VB程序设计教程

訪 談 後 的 檢 討 ~~~~~~~~~~~~~~~~p.18,19 2

附录J:Eclipse教程

第1章

untitled

Java

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

專題報告交版.doc

Microsoft Word - Broker.doc

epub83-1

(京)新登字063号

Business Objects 5.1 Windows BusinessObjects 1

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

EJB-Programming-4-cn.doc

(CIP) Web /,. :, ISBN X.W T P393.4 CIP (2004) Web ( ) ( / ) : * 787

untitled

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new

Learning Java

untitled

Java 1 Java String Date

Strings

5-1 nav css 5-2

untitled

Microsoft PowerPoint - course2.ppt

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

Microsoft Word 軟體設計第二部份範例試題_C++_ _1_.doc

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

untitled

epub 94-3

mvc

利用Java技术编写桌面软件基础

Microsoft Word - ch04三校.doc

Adobe® Flash® 的 Adobe® ActionScript® 3.0 程式設計

INTRODUCTION TO COM.DOC

全国计算机技术与软件专业技术资格(水平)考试

1. 2. Flex Adobe 3.

untitled

基于ECO的UML模型驱动的数据库应用开发1.doc

<4D F736F F F696E74202D C DB5DA3132D5C25FCDBCD0CED3C3BBA7BDE7C3E6BBF9B4A12E BBCE6C8DDC4A3CABD5D>

WinMDI 28

FIT1改1.FIT)

chp11.ppt

<4D F736F F F696E74202D20B5DA37D5C2204A617661B5C4CDBCD0CED3EBD3C3BBA7BDE7C3E62E BBCE6C8DDC4A3CABD5D>

Microsoft Word - 苹果脚本跟我学.doc

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

投影片 1

untitled

ZW1.PDF

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

SDS 1.3

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

untitled

Microsoft PowerPoint - Lecture7II.ppt

電機工程系認可證照清單 /7/1

[Short Essay:] 1. (5 points) Use state-of-memory diagram to describe the differences between x and y declared as follows: double[] x = new double[4];

App Flappy Bird 14 STEP Swift GameKit Xcode 5.1 Swift GameKit MyWord

影視後製全攻略 Premiere Pro After Effects Encore 自序 Adobe Premiere Pro After Effects Encore 2008 Adobe CS Adobe CS5 Adobe CS4 Premiere Pro After Effect

Microsoft Word - template.doc

2/14 Buffer I12, /* x=2, buffer = I 1 2 */ Buffer I243, /* x=34, buffer = I 2 43 */ x=56, buffer = I243 Buffer I243I265 code_int(int x, char *buffer)

内 容 提 要 将 JAVA 开 发 环 境 迁 移 到 Linux 系 统 上 是 现 在 很 多 公 司 的 现 实 想 法, 而 在 Linux 上 配 置 JAVA 开 发 环 境 是 步 入 Linux 下 JAVA 程 序 开 发 的 第 一 步, 本 文 图 文 并 茂 地 全 程 指

untitled

Text 文字输入功能 , 使用者可自行定义文字 高度, 旋转角度 , 行距 , 字间距离 和 倾斜角度。

EJB-Programming-3.PDF

ebook71-13

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 號 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

1.5招募说明书(草案)

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

Transcription:

Java 程式設計基礎班 (8) 莊坤達台大電信所網路資料庫研究室 Email: doug@arbor.ee.ntu.edu.tw Class 8 1 回顧 Java Data Structure Class 8 2

Java AWT package Component: 一些 GUI 元件, 如 : Button Label 等 Container: 用來放置 GUI 元件的地方 Container 可分為兩種供使用者使用 : Frame(Window): 一個開出來的視窗 Panel: 放在 Frame 裡的畫布, 一個 Frame 裡可以有多個 Panel Class 8 3 Java Swing package 修改自 awt 提供更強大的繪圖元件功能, 以及更穩定的函式庫 Swing Container 可分為兩種供使用者使用 : JFrame(Window): 一個開出來的視窗 JPanel: 放在 JFrame 裡的畫布, 一個 JFrame 裡可以有多個 JPanel Class 8 4

第一個小程式 JFrame 的使用 見 exercise8_1 Class 8 5 JPanel 的使用 見 exercise8_2 Class 8 6

Layout Managers 把元件放在我們希望放置的地方! FlowLayout:Panel 與 Applet 預設使用的 layout 方式 BorderLayout:Windows Dialogs 與 Frames 的預設使用的 layout 方式 GridLayout CardLayout GridBagLayout Null 不設定任何 Layout Class 8 7 FlowLayout Manager line by line basis 就是說元件一個接著一個的放在上面, 放滿了就會換行, 有點像打字超過一行字數會自動換行般 Class 8 8

import java.awt.*; public class MyFlow { private Frame f; private Button btn1, btn2, btn3; public static void main( String args[] ) { MyFlow aflow = new MyFlow(); aflow.go(); public void go() { f = new Frame( "FlowLayout Manager" ); // 使用 FlowLayout Manager, 對齊方式靠左,default 對齊方式為置中 f.setlayout( new FlowLayout( FlowLayout.LEFT ) ); btn1 = new Button( "Button1" ); // 產生三個按鈕 btn2 = new Button( "Button2" ); btn3 = new Button( "Button3" ); f.add( btn1 ); // 把 Button 加到 Frame 上 f.add( btn2 ); f.add( btn3 ); f.setsize( 100, 100 ); f.setvisible( true ); Class 8 9 Class 8 10

BorderLayout Manager BorderLayout 包含五種不同區域 : North,South,Ease,West,Center 元件的相對位置不會隨 window size 的改變而改變, 但元件的 size 將可能改變 看個例子 : Class 8 11 import java.awt.*; public class MyBorder { private Frame f; private Button btnnorth, btnsouth, btneast, btnwest, btncenter; public static void main( String args[] ) { MyBorder aborder = new MyBorder(); aborder.go(); [ next ] Class 8 12

public void go() { f = new Frame( "BorderLayout Manager" ); //Frame 預設使用 BorderLayout f.setlayout( new BorderLayout() ); // 採用 BorderLayout 的方式來排列元件 btnnorth = new Button( "ButtonNorth" ); btnsouth = new Button( "ButtonSouth" ); btneast = new Button( "ButtonEast" ); btnwest = new Button( "ButtonWest" ); btncenter = new Button( "ButtonCenter"); f.add( btnnorth, "North" ); f.add( btnsouth, "South" ); f.add( btneast, "East" ); f.add( btnwest, "West" ); f.add( btncenter, "Center" ); // 將五個按鈕分別加在五個位置上 f.setsize( 300, 100 ); f.setvisible( true ); Class 8 13 Class 8 14

GridLayout Manager 讓你在畫布上打格子, 元件就可以方便的放在特定的位置裡, 每個方格的大小是一樣的 加入順序 : 由左至右 / 由上至下 看個例子 : Class 8 15 import java.awt.*; public class MyGrid { private Frame f; private Button btn11, btn12, btn13; private Button btn21, btn22, btn23; public static void main( String args[] ) { MyGrid agrid = new MyGrid(); agrid.go(); public void go() { f = new Frame( "GridLayout Manager" ); // 使用 GridLayout 方式排列元件 // 將 Frame 分成 row=3, col=2 的區塊 f.setlayout( new GridLayout( 3, 2 ) ); [ next ] Class 8 16

btn11 = new Button( "Button(1,1)" ); btn12 = new Button( "Button(1,2)" ); btn13 = new Button( "Button(1,3)" ); btn21 = new Button( "Button(2,1)" ); btn22 = new Button( "Button(2,2)" ); btn23 = new Button( "Button(2,3)" ); // 將入六個按鈕, 加入順序 : 由左至右 / 由上至下 f.add( btn11 ); f.add( btn12 ); f.add( btn13 ); f.add( btn21 ); f.add( btn22 ); f.add( btn23 ); f.setsize( 300, 200 ); f.setvisible( true ); Class 8 17 Class 8 18

AWT/Swing Component Library Class 8 19 Button package AWT_Component; import java.awt.*; public class mybutton extends Frame { public static void main( String args[] ) { mybutton btnexam = new mybutton( "Button Example" ); Panel p = new Panel(); Button btn1 = new Button( "Sample" ); p.add( btn1 ); btnexam.add( p ); btnexam.setsize( 100, 100 ); btnexam.setvisible( true ); public mybutton( String title ) { super (title); Class 8 20

Class 8 21 Checkbox Class 8 22

import java.awt.*; public class mycheckbox extends Frame { public static void main( String args[] ) { mycheckbox chkboxexam = new mycheckbox( "CheckBox Example" ); Panel p = new Panel(); Checkbox chkbox1 = new Checkbox( "One", false ); Checkbox chkbox2 = new Checkbox( "Two", false ); Checkbox chkbox3 = new Checkbox( "Three", true ); p.add( chkbox1 ); p.add( chkbox2 ); p.add( chkbox3 ); chkboxexam.add( p ); chkboxexam.setsize( 300, 100 ); chkboxexam.setvisible( true ); public mycheckbox( String title ) { super (title); Class 8 23 true Class 8 24

CheckboxGroup - Radio Button Class 8 25 import java.awt.*; public class mycheckboxgroup extends Frame { public static void main( String args[] ) { mycheckboxgroup radiobtnexam = new mycheckboxgroup("checkbox Example"); Panel p = new Panel(); CheckboxGroup cbg = new CheckboxGroup(); Checkbox radiobtn1 = new Checkbox( "One", cbg, false ); Checkbox radiobtn2 = new Checkbox( "Two", cbg, false ); Checkbox radiobtn3 = new Checkbox( "Three", cbg, true ); p.add( radiobtn1 ); p.add( radiobtn2 ); p.add( radiobtn3 ); radiobtnexam.add( p ); radiobtnexam.setsize( 3100, 100 ); radiobtnexam.setvisible( true ); public mycheckboxgroup( String title ) { super (title); Class 8 26

Class 8 27 Choice:"select one from this list" Class 8 28

import java.awt.*; public class mychoice extends Frame { public static void main( String args[] ) { mychoice choiceexam = new mychoice( "Choice Example" ); Panel p = new Panel(); Choice c = new Choice(); c.additem( "First" ); c.additem( "Second" ); c.additem( "Three" ); p.add( c ); choiceexam.add( p ); choiceexam.setsize( 100, 100 ); choiceexam.setvisible( true ); public mychoice( String title ) { super (title); Class 8 29 Class 8 30

Label Class 8 31 import java.awt.*; public class mylabel extends Frame { public static void main( String args[] ) { mylabel labelexam = new mylabel( "Label Example" ); Panel p = new Panel(); Label label1 = new Label( "Sample" ); p.add( label1 ); labelexam.add( p ); labelexam.setsize( 100, 100 ); labelexam.setvisible( true ); public mylabel( String title ) { super (title); Class 8 32

Class 8 33 TextField Class 8 34

import java.awt.*; public class mytextfield extends Frame { public static void main( String args[] ) { mytextfield txtfieldexam = new mytextfield( "TextField Example" ); Panel p = new Panel(); TextField txtfield1 = new TextField( "Sample", 20 ); p.add( txtfield1 ); txtfieldexam.add( p ); txtfieldexam.setsize( 100, 100 ); txtfieldexam.setvisible( true ); public mytextfield( String title ) { super (title); Class 8 35 Class 8 36

TextArea Class 8 37 import java.awt.*; public class mytextarea extends Frame { public static void main( String args[] ) { mytextarea txtareaexam = new mytextarea( "TextArea Example" ); Panel p = new Panel(); TextArea txtarea1 = new TextArea( "Sample", 4, 20 ); p.add( txtarea1 ); txtareaexam.add( p ); txtareaexam.setsize( 100, 100 ); txtareaexam.setvisible( true ); public mytextarea( String title ) { super (title); Class 8 38

Class 8 39 List Class 8 40

import java.awt.*; public class mylist extends Frame { public static void main( String args[] ) { mylist listexam = new mylist( "List Example" ); Panel p = new Panel(); List c = new List( 3, true ); c.additem( "First" ); c.additem( "Second" ); c.additem( "Three" ); p.add( c ); listexam.add( p ); listexam.setsize( 100, 100 ); listexam.setvisible( true ); public mylist( String title ) { super (title); Class 8 41 Class 8 42

Dialog Class 8 43 import java.awt.*; public class mydialog extends Frame { public static void main( String args[] ) { mydialog dialogexam = new mydialog( "Dialog Example" ); Dialog dialog1 = new Dialog( dialogexam, "Sample", false ); dialog1.add( new Label( "Hello, Dialog..." ), "Center" ); dialog1.pack(); dialog1.setvisible( true ); dialogexam.setsize( 100, 100 ); dialogexam.setvisible( true ); public mydialog( String title ) { super (title); Class 8 44

Class 8 45 FileDialog Class 8 46

import java.awt.*; public class myfiledialog extends Frame { public static void main( String args[] ) { myfiledialog fdialogexam = new myfiledialog( "FileDialog Example" ); FileDialog fdialog1 = new FileDialog( fdialogexam, "Sample" ); fdialog1.setvisible( true ); String fname = fdialog1.getfile(); Panel p = new Panel(); Label l1 = new Label( fname ); p.add( l1 ); fdialogexam.add( p ); fdialogexam.setsize( 100, 100 ); fdialogexam.setvisible( true ); public myfiledialog( String title ) { super (title); Class 8 47 Class 8 48

ScrollPane Class 8 49 import java.awt.*; public class myscrollpane extends Frame{ public static void main( String args[] ) { myscrollpane spexam = new myscrollpane( "ScrollPane Example" ); Panel p = new Panel(); ScrollPane sp1 = new ScrollPane( ); p.setlayout( new GridLayout( 1, 1 ) ); Button b1 = new Button( "Btn1" ); Button b2 = new Button( "Btn2" ); Button b3 = new Button( "Btn3" ); Button b4 = new Button( "Btn4" ); p.add( b1 ); p.add( b2 ); p.add( b3 ); p.add( b4 ); sp1.add( p ); spexam.setlayout( new FlowLayout() ); spexam.add( sp1 ); spexam.setsize( 100, 100 ); spexam.setvisible( true ); public myscrollpane( String title ) { super (title); Class 8 50

Class 8 51 MenuBar Menu MenuItem Class 8 52

import java.awt.*; public class mymenu extends Frame{ public static void main( String args[] ) { mymenu menuexam = new mymenu( "Menu Bar/Menu/Menu Item" ); MenuBar mb = new MenuBar(); Menu m1 = new Menu( "File" ); Menu m2 = new Menu( "Edit" ); mb.add( m1 ); mb.add( m2 ); MenuItem m1_open = new MenuItem( "Open" ); MenuItem m1_save = new MenuItem( "Save" ); m1.add( m1_open ); m1.add( m1_save ); m1.addseparator(); m1.add( m1_exit ); menuexam.setmenubar( mb ); menuexam.setsize( 100, 100 ); menuexam.setvisible( true ); public mymenu( String title ) { super (title); Class 8 53 Class 8 54

PopupMenu Class 8 55 import java.awt.*; import java.awt.event.*; public class mypopupmenu extends Frame implements ActionListener { private Button b; private PopupMenu pop1; public static void main( String args[] ) { mypopupmenu popexam = new mypopupmenu( "PopupMenu Example" ); popexam.setsize( 100, 100 ); popexam.setvisible( true ); [ next page ] Class 8 56

public mypopupmenu( String title ) { super (title); pop1 = new PopupMenu( "Popup Sample" ); MenuItem s = new MenuItem( "Save" ); MenuItem l = new MenuItem( "Load" ); b = new Button( "Press me" ); add( b, "Center" ); b.addactionlistener( this ); pop1.add( s ); pop1.add( l ); add( pop1 ); public void actionperformed( ActionEvent ev ) { pop1.show( b, 10, 10 ); Class 8 57 Class 8 58

Color Controlling 設定 component 的顏色 setforeground(): 設定前景顏色 setbackgroud(): 設定背景顏色 自訂顏色 : RGB 三個參數 Red, Green, Blue, 範圍 :0 ~ 255 int r=255, g=255, b=0; Color c = new Color( r, g, b ); Class 8 59 import java.awt.*; public class mycolor extends Frame { public static void main( String args[] ) { mycolor btnexam = new mycolor( "Color Example" ); Panel p = new Panel(); Color newcolor = new Color( 200, 100, 0 ); Button btn1 = new Button( "Color ForeGround Green" ); Button btn2 = new Button( "Color BackGround Blue" ); Button btn3 = new Button( "Color BackGround User Define(200, 100, 0)" ); btn1.setforeground( Color.yellow ); btn2.setbackground( Color.blue ); btn3.setbackground( newcolor ); p.add( btn1 ); p.add( btn2 ); p.add( btn3 ); btnexam.add( p ); btnexam.setsize( 100, 100 ); btnexam.setvisible( true ); public mycolor( String title ) { super (title); Class 8 60

Class 8 61 Font Controlling 設定 component 上的字體, 包括 (Font Name/Style/Size) Class 8 62

import java.awt.*; public class myfont extends Frame { public static void main( String args[] ) { myfont btnexam = new myfont( "Font Example" ); Panel p = new Panel(); Font f1 = new Font( "Dialog", Font.BOLD, 25 ); Font f2 = new Font( "Courier", Font.ITALIC, 35 ); Font f3 = new Font( "TimesRoman", Font.PLAIN, 45 ); Button btn1 = new Button( "Font Dialog/BOLD/25 " ); Button btn2 = new Button( "Font Courier/ITALIC/35" ); Button btn3 = new Button( "Font TimesRoman/PLAIN/45" ); btn1.setfont( f1 ); btn2.setfont( f2 ); btn3.setfont( f3 ); p.add( btn1 ); p.add( btn2 ); p.add( btn3 ); btnexam.add( p ); btnexam.setsize( 100, 100 ); btnexam.setvisible( true ); public myfont( String title ) { super (title); Class 8 63 Class 8 64