⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydialog3.java

📁 SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本工程
💻 JAVA
字号:
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;
	}

	// 在这个方法里构建Dialog中的界面内容
	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);//省略了只能输入数值的限制
		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对象中
			if (human == null)
				human = new Human();
			human.setName(nameText.getText());
			human.setOld(Integer.parseInt(oldText.getText()));
			human.setSex(ggButton.getSelection());
		}
		super.buttonPressed(buttonId);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -