eclipse開発SWTアプリケーション
5142 ワード
公式サイト:http://www.eclipse.org/swt/
開発説明:http://www.eclipse.org/swt/eclipse.php
1.公式サイトにswt.zipファイルをダウンロードし、workspaceを導入する.
2.パスの選択
3.swtを追加する必要がある工程において、propertiesのJava Build Pathページはorg.eclipse.swtを含む.
4.org.eclipse.swtプロジェクトに依存して自分の工程でswtを使用する.
SWT例
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HelloSWT extends Shell{
private static Text text;
private static Button swtButton;
private static Button swingButton;
private static Button awtButton;
private static Group group;
private static Button button;
private static Label benefitOfSwtLabel;
private static List list;
public static void main(String[] args){
/*
* display , SWT Display , UI
* Display
*/
Display display = Display.getDefault();
/*
* Shell
*/
final Shell shell = new Shell(display);//
shell.setText("Hello SWT");
shell.setSize(260,283);// ,
shell.open();// ,
text = new Text(shell, SWT.BORDER);
text.setText("SWT Eclipse ");
text.setBounds(10, 8, 230, 35);
list = new List(shell, SWT.BORDER);
list.setItems(new String[]{
" ",
" API",
"GUI ",
" ......"});
list.setBounds(10, 68, 232, 82);
benefitOfSwtLabel = new Label(shell, SWT.BORDER);
benefitOfSwtLabel.setText("SWT :");
benefitOfSwtLabel.setBounds(10, 49, 90, 20);
group = new Group(shell, SWT.NONE);
group.setText(" ?");
group.setBounds(10, 159, 230, 47);
awtButton = new Button(group, SWT.CHECK);
awtButton.setText("AWT");
awtButton.setBounds(10, 20, 54, 18);
swingButton = new Button(group, SWT.CHECK);
swingButton.setText("Swing");
swingButton.setBounds(70, 22, 60, 15);
swtButton = new Button(group, SWT.CHECK);
swtButton.setText("SWT");
swtButton.setBounds(136, 22, 62, 15);
button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(final SelectionEvent e){
MessageBox msgBox = new MessageBox(shell, SWT.ICON_INFORMATION);
msgBox.setMessage("Hello SWT!");
msgBox.open();
}
});
button.setText(" , SWT Hello");
button.setBounds(10, 214, 227, 25);
shell.layout();//
// ,display
while(!shell.isDisposed()){// shell ,
/*
* , (TranslateMessage),
* , (DispatchMessage);
* , 。
* , ,
*/
if(!display.readAndDispatch()){
display.sleep();
}
}
// , shell ,( )
display.dispose();
}
}
結果: