?? mydialog3.java
字號(hào):
package cn.com.chengang.jface.dialog;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MyDialog3 extends Dialog {
private Human human;
private Text nameText;
private Text oldText;
private Button ggButton, mmButton;
public MyDialog3(Shell parentShell) {
super(parentShell);
}
public Human getInput() {
return this.human;
}
public void setInput(Human human) {
this.human = human;
}
// 在這個(gè)方法里構(gòu)建Dialog中的界面內(nèi)容
protected Control createDialogArea(Composite parent) {
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new GridLayout(2, false));
new Label(topComp, SWT.NONE).setText("姓名:");
nameText = new Text(topComp, SWT.BORDER);
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(topComp, SWT.NONE).setText("年齡:");
oldText = new Text(topComp, SWT.BORDER);//省略了只能輸入數(shù)值的限制
oldText.setLayoutData(new GridData(20,-1));
new Label(topComp, SWT.NONE).setText("性別:");
Composite c = new Composite(topComp, SWT.None);
c.setLayout(new RowLayout());
ggButton = new Button(c, SWT.RADIO);
ggButton.setText("男");
mmButton = new Button(c, SWT.RADIO);
mmButton.setText("女");
if (human != null) {
nameText.setText(human.getName() == null ? "" : human.getName());
oldText.setText(String.valueOf(human.getOld()));
ggButton.setSelection(human.isSex());
mmButton.setSelection(!human.isSex());
}
return topComp;
}
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {// 如果單擊確定按鈕,則將值保存到Human對(duì)象中
if (human == null)
human = new Human();
human.setName(nameText.getText());
human.setOld(Integer.parseInt(oldText.getText()));
human.setSex(ggButton.getSelection());
}
super.buttonPressed(buttonId);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -