关闭

一个简单的对话框JDialog

标签: JDialog
126人阅读 评论(0) 收藏 举报
分类:
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

public class ChooserSuccessDialog extends JDialog{

    public static ChooserSuccessDialog instance;
        initialize();
    }

    public static ChooserSuccessDialog instance(){
        if(null == instance){
            instance = new ChooserSuccessDialog();
        }
        return instance;
    }
    private void initialize() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int x = 300;
        int y = 200;
        setBounds(screenSize.width/2-x/2, screenSize.height/2-y/2, x, y);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
        Container c = getContentPane();
        c.setLayout(null);
        JLabel label = new JLabel("导入成功");
        label.setBounds(x/2-40, y/2-100, 100, 100);
        label.setFont(new Font(Font.DIALOG,Font.BOLD,15));
        JButton button = new JButton("确定");
        button.setBounds(115, 100, 60, 30);
        c.add(label);
        c.add(button);
        button.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }

        });
    }

    public static void main(String[] args) {
        ChooserSuccessDialog.instance();
    }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:57492次
    • 积分:1078
    • 等级:
    • 排名:千里之外
    • 原创:41篇
    • 转载:73篇
    • 译文:1篇
    • 评论:2条