Java語言的聲望和它在桌面應用程序(GUI程序)所取得的成就顯然極不相符
SWT本身僅僅是Eclipse組織為了開發Eclipse IDE環境所編寫的一組底層圖形界面 API
一是指性能上的穩定
另一個穩定是指SWT API包中的類
二
windows系統+eclipse
(
+swt
+bin(編譯輸出)
+src(原文件)
+AddressBookUI
+swt
+swt
+javaw
(
(
import org
import org
import org
import org
import org
import org
import org
import org
import org
import org
public class AddressBookUI {
private Shell shell;
private Text miscText;
private Text addrText;
private Text emailText;
private Text phoneText;
private Text lnameText;
private Text fnameText;
private Button cancelButton;
private Button saveButton;
private Button nextButton;
private Button prevButton;
private Button editButton;
private Button deleteButton;
private Button newButton;
public static void main(String[] args) {
AddressBookUI window = new AddressBookUI();
window
}
public void open() {
final Display display = new Display();
shell = new Shell();
shell
shell
{
newButton = new Button(shell
newButton
public void widgetSelected(SelectionEvent e) {
clearText();
setTextEditable(true);
enableEditButtons(false);
enableSaveButtons(true);
System
}
});
newButton
newButton
}
{
deleteButton = new Button(shell
deleteButton
public void widgetSelected(SelectionEvent e) {
clearText();
System
}
});
deleteButton
deleteButton
}
{
editButton = new Button(shell
editButton
public void widgetSelected(SelectionEvent e) {
setTextEditable(true);
enableEditButtons(false);
enableSaveButtons(true);
System
}
});
editButton
editButton
}
{
prevButton = new Button(shell
prevButton
public void widgetSelected(SelectionEvent e) {
System
}
});
prevButton
prevButton
}
{
nextButton = new Button(shell
nextButton
public void widgetSelected(SelectionEvent e) {
System
}
});
nextButton
nextButton
}
{
saveButton = new Button(shell
saveButton
public void widgetSelected(SelectionEvent e) {
setTextEditable(false);
enableEditButtons(true);
enableSaveButtons(false);
System
}
});
saveButton
saveButton
saveButton
}
{
cancelButton = new Button(shell
cancelButton
public void widgetSelected(SelectionEvent e) {
setTextEditable(false);
enableEditButtons(true);
enableSaveButtons(false);
System
}
});
cancelButton
cancelButton
cancelButton
}
{
final Group group = new Group(shell
group
group
{
final Label label = new Label(group
label
label
}
{
final Label label = new Label(group
label
label
}
{
final Label label = new Label(group
label
label
}
{
final Label label = new Label(group
label
label
}
{
final Label label = new Label(group
label
label
}
{
final Label label = new Label(group
label
label
}
{
fnameText = new Text(group
fnameText
}
{
lnameText = new Text(group
lnameText
}
{
phoneText = new Text(group
phoneText
}
{
emailText = new Text(group
emailText
}
{
addrText = new Text(group
addrText
}
{
miscText = new Text(group
miscText
}
}
setupMenu();
shell
while (!shell
if (!display
display
}
}
private void setupMenu() {
//create the menu bar
Menu menu = new Menu(shell
shell
//add the File option to it
MenuItem file = new MenuItem(menu
file
//create a menu for the File option
file
//add MenuItems to the File menu
MenuItem prevItem = new MenuItem(new Menu(file)
prevItem
MenuItem nextItem = new MenuItem(new Menu(file)
nextItem
MenuItem seperator = new MenuItem(new Menu(file)
MenuItem quitItem = new MenuItem(new Menu(file)
quitItem
//add listeners for the actions
prevItem
public void handleEvent(Event e) {
System
}
});
nextItem
public void handleEvent(Event e) {
System
}
});
quitItem
public void handleEvent(Event e) {
shell
}
});
}
private void clearText() {
fnameText
lnameText
phoneText
emailText
addrText
miscText
}
private void setTextEditable(boolean editable) {
fnameText
lnameText
phoneText
emailText
addrText
miscText
}
private void enableEditButtons(boolean enable) {
newButton
deleteButton
editButton
}
private void enableSaveButtons(boolean enable) {
saveButton
cancelButton
}
}
(
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28176.html