Contoh Program Message Dialog di Java

Contoh program berikut ini menampilkan jenis-jenis window pesan di Java. Window pesan (message dialog) antara lain bertipe warning message, information message, confirmation message, dan juga input message. Class yang digunakan adalah class JOptionPane.

Berikut ini tampilannya:
contoh-program-message-dialog-java

Berikut ini contoh programnya:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;



public class MessageDialog extends JFrame {

	private JButton tombol, btn2, btn3, btn4, btn5;

	

	public MessageDialog() {

		super ("Event Handling");

		

		Container container = getContentPane();

		container.setLayout(new FlowLayout());

				

		tombol = new JButton ("Message Dialog");

		tombol.addActionListener(

			new ActionListener() {

				public void actionPerformed (ActionEvent e) {

					JOptionPane.showMessageDialog (null,"Contoh Message Dialog");

				}

			}

		);

		container.add(tombol);

		

		btn2 = new JButton ("Warning Message");

		btn2.addActionListener(

			new ActionListener() {

				public void actionPerformed (ActionEvent e) {

					JOptionPane.showConfirmDialog(null, "Contoh Warning Message","Peringatan",

						JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE);

				}

			}

		);

		container.add(btn2);

		

		btn3 = new JButton ("Question Message");

		btn3.addActionListener(

			new ActionListener() {

				public void actionPerformed (ActionEvent e) {

					JOptionPane.showConfirmDialog(null, "Contoh Question Message","Pertanyaan",

						JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

				}

			}

		);

		container.add(btn3);

		

		btn4 = new JButton ("Information Message");

		btn4.addActionListener(

			new ActionListener() {

				public void actionPerformed (ActionEvent e) {

					JOptionPane.showConfirmDialog(null, "Contoh Information Message","Informasi",

						JOptionPane.NO_OPTION, JOptionPane.INFORMATION_MESSAGE);

				}

			}

		);

		container.add(btn4);

		

		btn5 = new JButton ("Input Dialog");

		btn5.addActionListener(

			new ActionListener() {

				public void actionPerformed (ActionEvent e) {

					String a = JOptionPane.showInputDialog("Input Nama : ");

					JOptionPane.showMessageDialog(null, a);

				}

			}

		);

		container.add(btn5);

		

		setSize (200,300);

		setLocationRelativeTo(null);

		setVisible (true);

	}

	

	public static void main (String arg[]) {

		MessageDialog test = new MessageDialog();

		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	

}

Semoga bermanfaat dan maju terus ilmu pengetahuan Indonesia

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading ... Loading ...
Java, Java Swing

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

5 Responses to “Contoh Program Message Dialog di Java”

Leave Comment

(required)

(required)


// Place This Code At The End Or After All Ad Zone Div Created