Tampilan Program
Berikut ini contoh programnya:
003 | import java.awt.event.*; |
007 | public class MessageDialog extends JFrame { |
009 | private JButton tombol, btn2, btn3, btn4, btn5; |
011 | public MessageDialog() { |
013 | super ( "Event Handling" ); |
015 | Container container = getContentPane(); |
017 | container.setLayout( new FlowLayout()); |
019 | tombol = new JButton ( "Message Dialog" ); |
021 | tombol.addActionListener( |
023 | new ActionListener() { |
025 | public void actionPerformed (ActionEvent e) { |
027 | JOptionPane.showMessageDialog ( null , "Contoh Message Dialog" ); |
035 | container.add(tombol); |
037 | btn2 = new JButton ( "Warning Message" ); |
039 | btn2.addActionListener( |
041 | new ActionListener() { |
043 | public void actionPerformed (ActionEvent e) { |
045 | JOptionPane.showConfirmDialog( null , "Contoh Warning Message" , "Peringatan" , |
047 | JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE); |
057 | btn3 = new JButton ( "Question Message" ); |
059 | btn3.addActionListener( |
061 | new ActionListener() { |
063 | public void actionPerformed (ActionEvent e) { |
065 | JOptionPane.showConfirmDialog( null , "Contoh Question Message" , "Pertanyaan" , |
067 | JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); |
077 | btn4 = new JButton ( "Information Message" ); |
079 | btn4.addActionListener( |
081 | new ActionListener() { |
083 | public void actionPerformed (ActionEvent e) { |
085 | JOptionPane.showConfirmDialog( null , "Contoh Information Message" , "Informasi" , |
087 | JOptionPane.NO_OPTION, JOptionPane.INFORMATION_MESSAGE); |
097 | btn5 = new JButton ( "Input Dialog" ); |
099 | btn5.addActionListener( |
101 | new ActionListener() { |
103 | public void actionPerformed (ActionEvent e) { |
105 | String a = JOptionPane.showInputDialog( "Input Nama : " ); |
107 | JOptionPane.showMessageDialog( null , a); |
119 | setLocationRelativeTo( null ); |
125 | public static void main (String arg[]) { |
127 | MessageDialog test = new MessageDialog(); |
129 | test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
Tidak ada komentar:
Posting Komentar