Predefine Dialog Box in Swing

0


It provides a message box, input box, and confirmation box in the Swing application.
JOptionPane is the base class to handle all these methods
Code For MessageDialog:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO adds your handling code here:
        JOptionPane.showMessageDialog(this,"Welcome in message box");
    }                                       
Code for Confirmation Dialog:-
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        int a = JOptionPane.showConfirmDialog(this, "do you want to submit data");
        if(a==0)
        {
            jLabel1.setText("YES");
        }
        else if(a==1)
        {
            jLabel1.setText("NO");
        }
        else
        {
            jLabel1.setText("CANCEL");
        }       
    }                                      
Code for InputDialog:-
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO adds your handling code here:
        String s = JOptionPane.showInputDialog(null,"Enter name");
        jLabel1.setText(s);
    }   
Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)