본문 바로가기

JAVA

JOptionPane 기본 실습 -메세지창 띄우기

// 띄우기 실습

import java.awt.BorderLayout;

 

import java.awt.EventQueue;

 

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.JButton;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

 

 

public class JOptionPaneEx extends JFrame {

 

        private JPanel contentPane;

 

        /**

         * Launch the application.

         */

        public static void main(String[] args) {

               EventQueue.invokeLater(new Runnable() {

                       public void run() {

                              try {

                                      JOptionPaneEx frame = new JOptionPaneEx();

                                      frame.setVisible(true);

                              } catch (Exception e) {

                                      e.printStackTrace();

                              }

                       }

               });

        }

 

        /**

         * Create the frame.

         */

        public JOptionPaneEx() {

               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

               setBounds(100, 100, 450, 300);

               contentPane = new JPanel();

               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

               setContentPane(contentPane);

               contentPane.setLayout(null);

              

               JButton btnNewButton = new JButton("New button");

               btnNewButton.addMouseListener(new MouseAdapter() {

                       @Override

                       public void mouseClicked(MouseEvent arg0) {       

 

 

  

//                            JOptionPane.showMessageDialog(JOptionPaneEx.this, "메세지", "타이틀", JOptionPane.INFORMATION_MESSAGE);     //메세지창 띄우기

 

 

 

 

 

 

                             

//                            int flag = JOptionPane.showConfirmDialog(JOptionPaneEx.this, "메세지", "타이틀!", JOptionPane.YES_NO_OPTION); //리턴값이 있음

//                            System.out.println(flag);

 

 

 

                             

 

 

 

 

 

 

//                            String flag = JOptionPane.showInputDialog(JOptionPaneEx.this, "메세지", "타이틀!", JOptionPane.YES_NO_OPTION); //입력받을수 있음

//                            System.out.println(flag);

 

 

 

                             

 

 

 

 

 

                              String[] buttonName = {"로그인", "회원가입"};

                             int flag = JOptionPane.showOptionDialog(JOptionPaneEx.this, "메세지", "타이틀", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, buttonName, buttonName[0]);

                              System.out.println(flag);

 

 

                             

                             

                             

                      

                       }

               });

               btnNewButton.setBounds(12, 10, 410, 23);

               contentPane.add(btnNewButton);

        }

}