eclipse中用swt designer,为控件添加事件处理程序的问题,在线等!!!
原先建了一个applicantwindow,在上面添加了控件button,然后添加事件处理程序,想弹出另外一个窗口/对话框,请问怎么弄?谢谢!还有,新弹出来的窗口还要往上...
原先建了一个applicant window ,在上面添加了控件 button,然后添加事件处理程序,想弹出另外一个窗口/对话框,请问怎么弄?谢谢!
还有,新弹出来的窗口还要往上面添加控件 展开
还有,新弹出来的窗口还要往上面添加控件 展开
2个回答
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
展开全部
用来打开对话框的窗口
package com.wojiushiwoltq;
import org.eclipse.swt.SWT;
/**
* 类说明
*
* @author WoJiuShiWoLtq
* @version 1.0
* @Date 2011 2011-4-22 下午04:50:58
*
*/
public class Test {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Test window = new Test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FormLayout());
Button button = new Button(composite,SWT.NONE);
{
FormData data = new FormData();
data.top = new FormAttachment(0, 10);
data.left=new FormAttachment(0, 10);
button.setLayoutData(data);
button.setText("按钮");
}
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new MyDialog(null).open();
}
});
}
}
对话窗口
package com.wojiushiwoltq;
import org.eclipse.jface.dialogs.Dialog;
/**
* 类说明
*
* @author WoJiuShiWoLtq
* @version 1.0
* @Date 2011 2011-4-22 下午04:56:16
*
*/
public class MyDialog extends Dialog {
/**
* Create the dialog.
* @param parentShell
*/
public MyDialog(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
return container;
}
/**
* Create contents of the button bar.
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
/**
* Return the initial size of the dialog.
*/
@Override
protected Point getInitialSize() {
return new Point(450, 300);
}
}
要在对话框里添加控件就在createDialogArea方法里加就可以了!
package com.wojiushiwoltq;
import org.eclipse.swt.SWT;
/**
* 类说明
*
* @author WoJiuShiWoLtq
* @version 1.0
* @Date 2011 2011-4-22 下午04:50:58
*
*/
public class Test {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Test window = new Test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FormLayout());
Button button = new Button(composite,SWT.NONE);
{
FormData data = new FormData();
data.top = new FormAttachment(0, 10);
data.left=new FormAttachment(0, 10);
button.setLayoutData(data);
button.setText("按钮");
}
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new MyDialog(null).open();
}
});
}
}
对话窗口
package com.wojiushiwoltq;
import org.eclipse.jface.dialogs.Dialog;
/**
* 类说明
*
* @author WoJiuShiWoLtq
* @version 1.0
* @Date 2011 2011-4-22 下午04:56:16
*
*/
public class MyDialog extends Dialog {
/**
* Create the dialog.
* @param parentShell
*/
public MyDialog(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
return container;
}
/**
* Create contents of the button bar.
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
/**
* Return the initial size of the dialog.
*/
@Override
protected Point getInitialSize() {
return new Point(450, 300);
}
}
要在对话框里添加控件就在createDialogArea方法里加就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询