怎样使用JDialog? 请高手给个源码 谢谢就是点击退出 按钮 出现“提示:确认 取消”对话框单击确认 实现退出我不知道这个事件的监听应该怎么写 还有怎么把确认事件与退出按钮联系到一起 呵呵谢谢高手 给个源码 我自己看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sizeDialog.dispose()不就实现了退出吗?---------------> public void actionPerformed(ActionEvent e) { sizeDialog.setVisible(false); sizeDialog.dispose(); } 这是我做项目的时候自己写的一个类,你可以拿过去参考一下....(你点某一按纽的时候,直接new一个对话框就是的)package view.dialog;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import view.com.CenterDialog;import view.frame.MainFrame;import action.implementclass.dialogaction.FaceSizeDialogActionImp;/** * 设定大小对话框 * @author linfeng * */public class FaceSizeDialog extends JDialog { /** * sizeDialog 大小对话框 * bg 按钮组 * extra_large 超大单选按钮 * large 大单选按钮 * medium 中单选按钮 * small 小单选按钮 * ok 确定按钮 * cancel 取消按钮 * topPanel 上面板 * bottomPanel 下面板 * bl 边界布局 */ public static JDialog sizeDialog; private ButtonGroup bg; public static JRadioButton extra_large, large, medium, small; private JButton ok, cancel; private JPanel topPanel, bottomPanel; private BorderLayout bl; public FaceSizeDialog() { sizeDialog = new JDialog(); //设定对话框大小 sizeDialog.setSize(400, 150); //让对话框居中显示 sizeDialog = new CenterDialog().getCenterDialog(sizeDialog, true); sizeDialog.setTitle("大小设置"); getTopPanel(); getBottomPanel(); bl = new BorderLayout(); sizeDialog.add(new JLabel("请选择界面大小:"), bl.NORTH); sizeDialog.add(topPanel, bl.CENTER); sizeDialog.add(bottomPanel, bl.SOUTH); sizeDialog.setVisible(true); } public void getTopPanel() { topPanel = new JPanel(); bg = new ButtonGroup(); extra_large = new JRadioButton("1024*768(默认)", true); large = new JRadioButton("800*600", false); medium = new JRadioButton("600*400", false); small = new JRadioButton("400*300", false); topPanel.setLayout(new FlowLayout()); bg.add(extra_large); bg.add(large); bg.add(medium); bg.add(small); topPanel.add(extra_large); topPanel.add(large); topPanel.add(medium); topPanel.add(small); } public void getBottomPanel() { bottomPanel = new JPanel(); ok = new JButton("确定"); cancel = new JButton("取消"); bottomPanel.setLayout(new FlowLayout()); bottomPanel.add(ok); bottomPanel.add(cancel); ok.addActionListener(new FaceSizeDialogActionImp()); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sizeDialog.setVisible(false); sizeDialog.dispose(); } }); }} 看下面这段代码吧:***.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { int value = 0; //默认不弹出提示 value=JOptionPane.showConfirmDialog(null, "您确定要退出吗?", "提示信息!",JOptionPane.YES_NO_OPTION); //0为确定,1为取消 if (value==0) { //点击确定将做的操作 yourDialog.dispose(); } if (value==1) { //点击取消将做的操作----nothing now. } } });其中***为要加入这个动作侦听的元件,比如按钮;yourDialog为你要关闭的那个视窗 java方法初始化问题 java 2d 绘图疑问 如何监听窗口变大变小以后的事件或窗口上的控件居中 有没有统一的录入界面??? 字符串 getBytes() 的问题 一个正则表达式的问题 十分紧急,JScrollPane的问题高分相送,在线等!! 急!! 有关Float.parseFloat(String s) JAVA 画线时如何设定线的种类? 高手请看这段代码如何错了?(等待中) 如果没有安装J以VM,怎么运行java程序 关于jscrollpane中jtable显示的问题
--------------->
public void actionPerformed(ActionEvent e) {
sizeDialog.setVisible(false);
sizeDialog.dispose();
}
(你点某一按纽的时候,直接new一个对话框就是的)
package view.dialog;import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;import view.com.CenterDialog;
import view.frame.MainFrame;
import action.implementclass.dialogaction.FaceSizeDialogActionImp;/**
* 设定大小对话框
* @author linfeng
*
*/
public class FaceSizeDialog extends JDialog { /**
* sizeDialog 大小对话框
* bg 按钮组
* extra_large 超大单选按钮
* large 大单选按钮
* medium 中单选按钮
* small 小单选按钮
* ok 确定按钮
* cancel 取消按钮
* topPanel 上面板
* bottomPanel 下面板
* bl 边界布局
*/
public static JDialog sizeDialog;
private ButtonGroup bg;
public static JRadioButton extra_large, large, medium, small;
private JButton ok, cancel;
private JPanel topPanel, bottomPanel;
private BorderLayout bl; public FaceSizeDialog() { sizeDialog = new JDialog();
//设定对话框大小
sizeDialog.setSize(400, 150);
//让对话框居中显示
sizeDialog = new CenterDialog().getCenterDialog(sizeDialog, true);
sizeDialog.setTitle("大小设置");
getTopPanel();
getBottomPanel();
bl = new BorderLayout();
sizeDialog.add(new JLabel("请选择界面大小:"), bl.NORTH);
sizeDialog.add(topPanel, bl.CENTER);
sizeDialog.add(bottomPanel, bl.SOUTH);
sizeDialog.setVisible(true);
} public void getTopPanel() {
topPanel = new JPanel();
bg = new ButtonGroup();
extra_large = new JRadioButton("1024*768(默认)", true);
large = new JRadioButton("800*600", false);
medium = new JRadioButton("600*400", false);
small = new JRadioButton("400*300", false);
topPanel.setLayout(new FlowLayout());
bg.add(extra_large);
bg.add(large);
bg.add(medium);
bg.add(small);
topPanel.add(extra_large);
topPanel.add(large);
topPanel.add(medium);
topPanel.add(small);
} public void getBottomPanel() {
bottomPanel = new JPanel();
ok = new JButton("确定");
cancel = new JButton("取消");
bottomPanel.setLayout(new FlowLayout());
bottomPanel.add(ok);
bottomPanel.add(cancel); ok.addActionListener(new FaceSizeDialogActionImp()); cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sizeDialog.setVisible(false);
sizeDialog.dispose();
}
});
}
}
public void mouseClicked(MouseEvent evt) {
int value = 0; //默认不弹出提示
value=JOptionPane.showConfirmDialog(null, "您确定要退出吗?", "提示信息!",JOptionPane.YES_NO_OPTION);
//0为确定,1为取消
if (value==0)
{
//点击确定将做的操作
yourDialog.dispose();
}
if (value==1)
{
//点击取消将做的操作----nothing now.
}
}
});其中***为要加入这个动作侦听的元件,比如按钮;
yourDialog为你要关闭的那个视窗