Show Dialog Box in Java swing
Previous Home Next


In the Swing the Message dialog box is used to display messages to the user. In this section we are using JOptionPane class to display the message Dialog box. Our program display "Click On Me" button on the window and when user clicks on it program 

displays Message box with "OK" button and message "R4RTech Soft Solution". 

This method is used to display a simple message.
This method is used to display a prompt for inputting and returns a String value which is entered by user.
This method is used to asks the user for confirmation (Yes/No) by displaying message. 


package r4r;
import javax.swing.*;
import java.awt.event.*;

public class showdialogbox {
	JFrame frame;
	  public static void main(String[] args){
		  showdialogbox sdb = new showdialogbox();

	  public showdialogbox(){
	  frame = new JFrame("Show Message Dialog");
	  JButton button = new JButton("Click on Me");
	  button.addActionListener(new MyAction());
	  frame.setSize(500, 500);

	  public class MyAction implements ActionListener{
	  public void actionPerformed(ActionEvent e){
	  JOptionPane.showMessageDialog(frame,"R4RTech Soft Solution");

Click on Me

R4RTech Soft Solution
Previous Home Next