eclipse中用swt designer,为控件添加事件处理程序的问题,在线等!!!
原先建了一个applicantwindow,在上面添加了控件button,然后添加事件处理程序,想弹出另外一个窗口/对话框,请问怎么弄?谢谢!还有,新弹出来的窗口还要往上...
原先建了一个applicant window ,在上面添加了控件 button,然后添加事件处理程序,想弹出另外一个窗口/对话框,请问怎么弄?谢谢!
还有,新弹出来的窗口还要往上面添加控件 展开
还有,新弹出来的窗口还要往上面添加控件 展开
2个回答
展开全部
用来打开对话框的窗口
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方法里加就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询