myeclipse写弹窗提示代码
时间: 2023-11-22 20:05:41 浏览: 49
你可以使用 JOptionPane 类来创建弹窗提示。下面是一个示例代码:
```java
import javax.swing.JOptionPane;
public class PopupDialog {
public static void main(String[] args) {
// 显示一个简单的信息提示框
JOptionPane.showMessageDialog(null, "欢迎使用 MyEclipse!");
// 显示一个带有“是”和“否”按钮的确认对话框
int result = JOptionPane.showConfirmDialog(null, "确定要退出 MyEclipse 吗?");
if (result == JOptionPane.YES_OPTION) {
System.exit(0);
}
// 显示一个带有文本输入框的输入对话框
String name = JOptionPane.showInputDialog(null, "请输入您的名字:");
if (name != null && !name.isEmpty()) {
JOptionPane.showMessageDialog(null, "您好," + name + "!");
}
}
}
```
这个示例代码中,`showMessageDialog` 方法用于显示一个简单的信息提示框,`showConfirmDialog` 方法用于显示一个带有“是”和“否”按钮的确认对话框,`showInputDialog` 方法用于显示一个带有文本输入框的输入对话框。你可以根据自己的需要选择使用哪种对话框。