sads

Wednesday, 22 February 2017

Confirmation Box









import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class ActionConfDialog extends JFrame implements ActionListener {


    JFrame jf;
    JPanel panel;
    JButton b1;
    JLabel l1;
   
   
    public ActionConfDialog() {
        // TODO Auto-generated constructor stub
        jf=new JFrame();
        setTitle("Confirmation box");
        setVisible(true);
        setSize(300, 200);
        setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
   
       
        l1=new JLabel();
        b1=new JButton("Confirmation dialog");
        b1.addActionListener(this);
       
       
   
    add(b1);
    add(l1);

    }
   
   
   
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
ActionConfDialog ac=new ActionConfDialog();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
       
       
       
       
        if (e.getSource()==b1) {
           
           
        int res=    JOptionPane.showConfirmDialog(null, "Do you want to save ?", "Confirm Box", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
       
               
               
               
                if (res==JOptionPane.YES_OPTION) {
                   
                    l1.setText("you saved the program");
                   
                }else {
                    l1.setText("you did nt save the program ");
                }
        }
    }

}
 

1 comment: