Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Predefine Dialog Box in Swing:-

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);
    }   



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post