java简单对话框Dialog设计

java标准对话框JOptionPane的简单设计

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JOptionPane implements ActionListener {

    JFrame frame = null;
    JPanel panel =null;
    JRadioButton buttonMessage = null;
    JRadioButton buttonConfirm = null;
    JRadioButton buttonOption = null;
    JRadioButton buttonInput = null;

    JOptionPane(){
        frame = new JFrame("对话框");
        panel = new JPanel();
        buttonMessage = new JRadioButton("Message");
        buttonConfirm = new JRadioButton("Confirm");
        buttonOption = new JRadioButton("Option");
        buttonInput = new JRadioButton("Input");


        frame.add(panel);
        panel.add(buttonMessage);
        panel.add(buttonConfirm);
        panel.add(buttonOption);
        panel.add(buttonInput);


        buttonMessage.addActionListener(this);//buttonMessage按钮监听
        buttonConfirm.addActionListener(this);//buttonConfirm按钮监听
        buttonOption.addActionListener(this);//buttonOption按钮监听
        buttonInput.addActionListener(this);//buttonInput按钮监听

        frame.setSize(400,200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
    }
//事件处理
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == buttonMessage) {
        JOptionPane.showMessageDialog(frame, "添加数据成功", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
    } else if (e.getSource() == buttonConfirm) {
        JOptionPane.showConfirmDialog(frame, "是否删除这些数据", "确认对话框", JOptionPane.WARNING_MESSAGE);
    } else if (e.getSource() == buttonOption) {
        Object[] option = {"保存", "不保存", "取消"};
        JOptionPane.showOptionDialog(frame, "是否保存这些数据", "确认对话框", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
    } else if (e.getSource() == buttonInput) {
        JOptionPane.showInputDialog(frame,"请输入要保存的数据","输入对话框",JOptionPane.QUESTION_MESSAGE);

    }
}


    public static void main(String[] args) {
        new JOptionPane();
    }
}
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值