Student Of Fortune

Sample Program Message Dialog In Java

Share on :
Example The following program shows the kinds of messages window in Java . Window message (message dialog), among others, type warning messages, information messages, the confirmation message, and also the input message. Class that is used is the class JOptionPane.

Here's how it looks:

contoh-program-message-dialog-java 
  
Here is an example program :

import java.awt .*;
import java.awt.event .*;
import javax.swing .*;
public class extends JFrame {MessageDialog
private JButton button, btn2, btn3, btn4, btn5;
public MessageDialog () {
super ("Event Handling");
Container container = getContentPane ();
container.setLayout (new FlowLayout ());
button = new JButton ("Message Dialog");
tombol.addActionListener (
new ActionListener () {
public void actionPerformed (ActionEvent e) {
JOptionPane.showMessageDialog (null, "Message Dialog Example");
}
}
);
container.add (button);
btn2 = new JButton ("Warning Message");
btn2.addActionListener (
new ActionListener () {
public void actionPerformed (ActionEvent e) {
JOptionPane.showConfirmDialog (null, "Sample Warning Message", "Warning",
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, "Sample Question Message", "Question",
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, "Sample Information Message", "Information",
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 Name:");
JOptionPane.showMessageDialog (null, a);
}
}
);
container.add (btn5);
setSize (200.300);
setLocationRelativeTo (null);
setVisible (true);
}
public static void main (String arg []) {
MessageDialog MessageDialog test = new ();
test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
}

0 comments on Sample Program Message Dialog In Java :

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank