SWT學(xué)習(xí)筆記之二
至從寫了swt學(xué)習(xí)筆記(一)之后,好久都沒有再寫blog了,可謂這個(gè)之(二)是姍姍來遲啊
^_^,以后會(huì)盡快地把后面的內(nèi)容都補(bǔ)上 。這主要寫下一些簡(jiǎn)單的控件……
Label:label是不能被用戶所修改的
label的用法:
Label label1 = new Label(shell, styles);
其中styles可以為BORDER, CENTER, LEFT, RIGHT, WRAP 和 SEPARATOR
其中SWT.SEPARATOR 為一條線 當(dāng)styles為SEPARATOR時(shí),可以加入 HORIZONTAL(水平的),VERTICAL, SHADOW_IN, SHADOW_OUT and SHADOW_NONE.屬性
Text: 一般用法 Text text1 = new Text(shell, styles);
其中styles的屬性值可以為BORDER, H_SCROLL, V_SCROLL, MULTI,SINGLE, READ_ONLY and WRAP.等
如果想設(shè)置為密碼輸入框,則加上方法text2.setEchoChar('*');即可
Button:一般用法為Button button1 = new Button(shell,styles);
其中styles可以為 PUSH, CHECK, RADIO, TOGGLE and ARROW
注意setBounds(橫坐標(biāo),縱坐標(biāo),長(zhǎng)度,寬度)可以代替setLocation(0,0);setSize(100,20);兩個(gè)方法
button最基本的事件句柄是selection event handler,當(dāng)用戶點(diǎn)擊按鈕被選中時(shí),調(diào)用這個(gè)selection event handler,為了創(chuàng)建一個(gè)selection event handler.
要?jiǎng)?chuàng)建一個(gè)監(jiān)聽器listener,一般采用下面的代碼:
button1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Button1 was clicked");
}
});
List: List包含了一些項(xiàng)目的集合,一般用法為:List list1 = new List(shell, styles);
其中styles可以為:BORDER, H_SCROLL, V_SCROLL,SINGLE and MULTI
可以用list1.setItems(new String[] {"Strawberry","Banana","Apple"});list1.add("Pickle");這兩個(gè)方法來向List中加入數(shù)據(jù)
在List中可以用MouseListener來響應(yīng)項(xiàng)目被點(diǎn)擊所引發(fā)的事件,MouseListener包括MouseDown and MouseUp events
一般的代碼為模式為:
list2.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
System.out.println(list2.getSelection()[0] +" wins");
}
public void mouseUp(MouseEvent e) {
System.out.println("Try again!");
}
});
composite:它既是一個(gè)組件,也是一個(gè)容器,也即是說,在它里面還可以放置其他組件
Group: group是composite的一個(gè)子類,他最主要的目的是和其他組件分隔開,group也是一個(gè)容器,也是一個(gè)組件,放在它里面的組件的位置全都是相對(duì)位置
^_^,以后會(huì)盡快地把后面的內(nèi)容都補(bǔ)上 。這主要寫下一些簡(jiǎn)單的控件……
Label:label是不能被用戶所修改的
label的用法:
Label label1 = new Label(shell, styles);
其中styles可以為BORDER, CENTER, LEFT, RIGHT, WRAP 和 SEPARATOR
其中SWT.SEPARATOR 為一條線 當(dāng)styles為SEPARATOR時(shí),可以加入 HORIZONTAL(水平的),VERTICAL, SHADOW_IN, SHADOW_OUT and SHADOW_NONE.屬性
Text: 一般用法 Text text1 = new Text(shell, styles);
其中styles的屬性值可以為BORDER, H_SCROLL, V_SCROLL, MULTI,SINGLE, READ_ONLY and WRAP.等
如果想設(shè)置為密碼輸入框,則加上方法text2.setEchoChar('*');即可
Button:一般用法為Button button1 = new Button(shell,styles);
其中styles可以為 PUSH, CHECK, RADIO, TOGGLE and ARROW
注意setBounds(橫坐標(biāo),縱坐標(biāo),長(zhǎng)度,寬度)可以代替setLocation(0,0);setSize(100,20);兩個(gè)方法
button最基本的事件句柄是selection event handler,當(dāng)用戶點(diǎn)擊按鈕被選中時(shí),調(diào)用這個(gè)selection event handler,為了創(chuàng)建一個(gè)selection event handler.
要?jiǎng)?chuàng)建一個(gè)監(jiān)聽器listener,一般采用下面的代碼:
button1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Button1 was clicked");
}
});
List: List包含了一些項(xiàng)目的集合,一般用法為:List list1 = new List(shell, styles);
其中styles可以為:BORDER, H_SCROLL, V_SCROLL,SINGLE and MULTI
可以用list1.setItems(new String[] {"Strawberry","Banana","Apple"});list1.add("Pickle");這兩個(gè)方法來向List中加入數(shù)據(jù)
在List中可以用MouseListener來響應(yīng)項(xiàng)目被點(diǎn)擊所引發(fā)的事件,MouseListener包括MouseDown and MouseUp events
一般的代碼為模式為:
list2.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
System.out.println(list2.getSelection()[0] +" wins");
}
public void mouseUp(MouseEvent e) {
System.out.println("Try again!");
}
});
composite:它既是一個(gè)組件,也是一個(gè)容器,也即是說,在它里面還可以放置其他組件
Group: group是composite的一個(gè)子類,他最主要的目的是和其他組件分隔開,group也是一個(gè)容器,也是一個(gè)組件,放在它里面的組件的位置全都是相對(duì)位置
posted on 2007-06-14 14:46 何晏成 閱讀(402) 評(píng)論(1) 編輯 收藏