//창 띄우기 실습
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);
}
}
'JAVA' 카테고리의 다른 글
JTable 기본 실습 (0) | 2013.02.08 |
---|---|
스윙 관련 강의자료 (pdf) (0) | 2013.02.07 |
[실습]주민등록번호 검사기 -GUI구현 (0) | 2013.02.06 |
이벤트(Event) 기본 실습(마우스 리스너 구현 5가지) (0) | 2013.02.06 |
JFrame 기본 실습 -버튼달기 (0) | 2013.02.06 |