swt-jface (1)窗口的組成部分
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class test_swt {
public static void main(String[] args) {
Display display=new Display();
final Shell shell=new Shell();
shell.setSize(600,300);
shell.setText("標(biāo)題");
shell.layout();
//打開主窗口
shell.open();
//創(chuàng)建其他組件
Button button = new Button(shell, SWT.NONE);
//設(shè)定按鈕上的字體
button.setText("確定");
//設(shè)置按鈕文字的提示性語(yǔ)句
button.setToolTipText("按鈕提示性語(yǔ)句");
//設(shè)定按鈕在主窗口上的位置
button.setBounds(300, 120, 60, 30);
button.addSelectionListener(new SelectionAdapter(){//添加按鈕監(jiān)聽(tīng)(使用內(nèi)部類方法)
public void widgetSelected(SelectionEvent e){
MessageDialog.openInformation(shell, "彈出窗口標(biāo)題", "彈出窗口的內(nèi)容");
}
});
//如果shell主窗口沒(méi)有關(guān)閉,則一直循環(huán)
while(!shell.isDisposed()){
//如果Display不忙,就讓Display處于休眠狀態(tài)
if(!display.readAndDispatch()){
display.sleep();
}
}
//釋放Display的資源
display.dispose();
}
}
posted on 2009-11-28 13:46 javaz 閱讀(315) 評(píng)論(0) 編輯 收藏 所屬分類: javaSE