Message Box Type Demonstration

A tutorial how to make a demonstration of different types of message boxes. It enables the user to view an icon on the message box by clicking the button.

So, Open your Netbeans IDE and create a New Project and JFrame.

Step 1:
Add 1 JLabel, 5 JButtons. Right Click then follow the instruction below:

EDIT TEXT                               CHANGE VARIABLE NAME
Information Message                  btnInfo
Warning Message                        btnWarn
Error Message                             btnErr
Confirm Message                        btnConf
Input Message                             btnIn



Step 2:

In the Source Code, add first the

import javax.swing.JOptionPane;

before the public class
then copy this code.



private void btnInfoActionPerformed(java.awt.event.ActionEvent evt) {                                        
        JOptionPane.showMessageDialog(null,"Information Message","code-devs.blogspot.com",JOptionPane.INFORMATION_MESSAGE);
    }                                      

    private void btnWarnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        JOptionPane.showMessageDialog(null,"Warning Message","code-devs.blogspot.com",JOptionPane.WARNING_MESSAGE);
    }                                      

    private void btnErrActionPerformed(java.awt.event.ActionEvent evt) {                                      
        JOptionPane.showMessageDialog(null,"Error Message","code-devs.blogspot.com",JOptionPane.ERROR_MESSAGE);
    }                                     

    private void btnConfActionPerformed(java.awt.event.ActionEvent evt) {                                       
        int message = JOptionPane.showConfirmDialog(null,"Confirm Messasge","code-devs.blogspot.com",JOptionPane.ERROR_MESSAGE);
if (message == JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
{
System.exit(0);
}
    }                                      

    private void btnInActionPerformed(java.awt.event.ActionEvent evt) {                                     
        String name = JOptionPane.showInputDialog(null,"Input Dialog Message","code-devs.blogspot.com",JOptionPane.WARNING_MESSAGE);
System.exit(0);
    }                    
Final Output:



Message Box Type Demonstration Message Box Type Demonstration Reviewed by code-dev on 5:04 PM Rating: 5

No comments:

Powered by Blogger.