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 contoh programnya:
001
|
import java.awt.*;
|
|
002
|
|
003
|
import java.awt.event.*;
|
|
004
|
|
005
|
import javax.swing.*;
|
|
006
|
|
007
|
public class MessageDialog
extends JFrame {
|
|
008
|
|
009
|
private JButton
tombol, btn2, btn3, btn4, btn5;
|
|
010
|
|
011
|
public MessageDialog()
{
|
|
012
|
|
013
|
super ("Event
Handling");
|
|
014
|
|
015
|
Container
container = getContentPane();
|
|
016
|
|
017
|
container.setLayout(new FlowLayout());
|
|
018
|
|
019
|
tombol
= new JButton ("Message Dialog");
|
|
020
|
|
021
|
tombol.addActionListener(
|
|
022
|
|
023
|
new ActionListener()
{
|
|
024
|
|
025
|
public void actionPerformed
(ActionEvent e) {
|
|
026
|
|
027
|
JOptionPane.showMessageDialog
(null,"Contoh Message Dialog");
|
|
028
|
|
029
|
}
|
|
030
|
|
031
|
}
|
|
032
|
|
033
|
);
|
|
034
|
|
035
|
container.add(tombol);
|
|
036
|
|
037
|
btn2
= new JButton ("Warning Message");
|
|
038
|
|
039
|
btn2.addActionListener(
|
|
040
|
|
041
|
new ActionListener()
{
|
|
042
|
|
043
|
public void actionPerformed
(ActionEvent e) {
|
|
044
|
|
045
|
JOptionPane.showConfirmDialog(null,
"Contoh Warning Message","Peringatan",
|
|
046
|
|
047
|
JOptionPane.CLOSED_OPTION,
JOptionPane.WARNING_MESSAGE);
|
Thanks for reading & sharing KEPOIN IT
0 comments:
Post a Comment