Message Box

import java.awt.event.*;
import javax.swing.*;
public class DialogDemo1 extends JApplet implements ActionListener {
	JPanel p1;
	JButton b[];

	@Override
	public void init() {
		super.init();
		b = new JButton[7];
		getContentPane().add(p1 = new JPanel());
		b[0] = new JButton("MessageDialog");
		b[1] = new JButton("InternalMessageDialog");
		b[2] = new JButton("ConfirmDialog");
		b[3] = new JButton("InputDialog");
		b[4] = new JButton("InputDialog -1");
		b[5] = new JButton("OptionDialog");
		b[6] = new JButton("Exit");

		for (int i = 0; i < b.length; i++) {
			p1.add(b[i]);
			b[i].addActionListener(this);
		}

	}

	@Override
	public void actionPerformed(ActionEvent evt) {
		Object obj = evt.getSource();
		if (obj == b[0]) {
			JOptionPane.showMessageDialog(null, "Show Message Dialog", "alert",
					JOptionPane.ERROR_MESSAGE);
		}
		if (obj == b[1]) {
			JOptionPane.showInternalMessageDialog(this, "Internal Dialog",
					"internal", JOptionPane.INFORMATION_MESSAGE);

		}
		if (obj == b[2]) {
			JOptionPane.showConfirmDialog(null, "Confirm Dialog", "choose one",
					JOptionPane.YES_NO_OPTION);
		}
		if (obj == b[3]) {
			String str = JOptionPane.showInputDialog("Enter a message");
			if (str != null && str.length() != 0)
				JOptionPane.showConfirmDialog(null, str);
		}
		if (obj == b[4]) {
			String str1 = (String) JOptionPane.showInputDialog(null,
					"Please choose a server", "dialog example",
					JOptionPane.QUESTION_MESSAGE, null, new Object[] {
							"Server1", "Server2", "Server3", "Server4",
							"Server5", "Server6", "Server7", "Server8",
							"Server9", "Server10" }, 1);
			if (str1 != null)
				JOptionPane.showConfirmDialog(null, str1);
		}
		if (obj == b[5]) {
			Object[] options = { "OK", "CANCEL" };
			JOptionPane.showOptionDialog(null, "Click OK to continue",
					"Warning", JOptionPane.DEFAULT_OPTION,
					JOptionPane.WARNING_MESSAGE, null, options, options[0]);
		}
		if (obj == b[6]) {
			System.exit(0);
		}
	}
}

Download

Message Box in Java

Message Dialog,InternalMessage Dialog box,Confirm Dialog,Input Dialog,Option Dialog


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code