sads

Wednesday, 22 February 2017

Dialog _ INPUT DIALOG BOXty











































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;

public class Dialogs extends JFrame implements ActionListener {


   
    JFrame jf;
    JButton b1;
    JLabel l1;
   
   
   
   
   
    public Dialogs() {
        // TODO Auto-generated constructor stub
   
    jf=new JFrame();
    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
Dialogs d=new Dialogs();
    }





    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
       
       
        if (e.getSource()==b1) {
           
            int i=JOptionPane.QUESTION_MESSAGE;
            String s=JOptionPane.showInputDialog(jf, "What is u r name?", "Question", i);
           
            l1.setText("u r name is "+s);
        }
       
       
       
       
       
    }

}

No comments:

Post a Comment