为什么我点击了“确定”按钮并没有弹出另外一个窗口?(java eclipse 中)
importorg.eclipse.jface.dialogs.MessageDialog;importorg.eclipse.swt.SWT;importorg.ecl...
import org.eclipse.jface.dialogs.MessageDialog;
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.Shell;
public class HelloWorld {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("Hello World");
Button button = new Button(shell, SWT.NONE);
button.setText("确定");
button.setBounds(88, 94, 100, 25);
button.addSelectionListener(new SelectionAdapter() {
public void windgetSelected(SelectionEvent e) {
MessageDialog.openInformation(shell,"hello","helloworld");
}
});
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} 展开
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.Shell;
public class HelloWorld {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("Hello World");
Button button = new Button(shell, SWT.NONE);
button.setText("确定");
button.setBounds(88, 94, 100, 25);
button.addSelectionListener(new SelectionAdapter() {
public void windgetSelected(SelectionEvent e) {
MessageDialog.openInformation(shell,"hello","helloworld");
}
});
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} 展开
3个回答
展开全部
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent arg0) {
MessageBox message=new MessageBox(shell, SWT.ICON_INFORMATION);
message.setMessage("helloWorld");
message.setText("hello");
message.open();
}
});
我是这样的,你可以试试
public void widgetSelected(final SelectionEvent arg0) {
MessageBox message=new MessageBox(shell, SWT.ICON_INFORMATION);
message.setMessage("helloWorld");
message.setText("hello");
message.open();
}
});
我是这样的,你可以试试
展开全部
button.addActionListener(ActionListener l) 加错监听了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
button 没有addSelectionListener()方法
只有:
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
这里设置弹出对话框!!!!
}
});
只有:
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
这里设置弹出对话框!!!!
}
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询