import java.awt.Button; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Dialog { private String icon; private String title; private String message; private Button submit; private Button cancel; private Button close; private Dialog(){ } private Dialog(String icon, String title, String message, Button submit, Button cancel, Button close) { this.icon = icon; this.title = title; this.message = message; this.submit = submit; this.cancel = cancel; this.close = close; this.submit = new Button(); // 初始化submit按钮 this.cancel = new Button(); // 初始化cancel按钮 this.close = new Button(); // 初始化close按钮 } public void show(){ //弹出 } public void dismiss(){ //关闭 } static class Builder{ private Dialog dialog = new Dialog(); public Builder title(String title){ dialog.setTitle(title); return this; } public Builder icon(String icon){ dialog.setIcon(icon); return this; } public Builder message(String message){ dialog.setMessage(message); return this; } public Dialog build(){ return dialog; } } public void setSubmitText(String text){ submit.setLabel(text); } public void setCancelText(String text){ cancel.setLabel(text); } public void setCloseText(String text){ close.setLabel(text); } /** * 回调函数 * @param callback */ public void addListenerOnSubmit(SubmitCallBackListener callback){ submit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //当用户对按钮执行了动作操作以后, //程序会到此处执行 callback.submitCallback(e); } }); } public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }这段代码怎么在myeclipse中运行出对话框
时间: 2023-12-30 21:03:32 浏览: 161
第5章 Java用户界面类和Applet-v2.1.ppt
这段代码只是定义了一个 Dialog 类,它包含了对话框的基本属性和方法,但并没有实现对话框的显示和交互逻辑。你需要在这个类的 show() 方法中添加对话框的显示逻辑,可以使用 Java 的 GUI 库(如 Swing 或 JavaFX)来创建对话框的 UI,并在 submit、cancel、close 按钮的点击事件中添加对应的交互逻辑。具体实现方式可以参考 Java GUI 相关的教程和示例代码。
阅读全文