반응형
입력 - JOptionPane.showInputDialog()
확인 - JOptionPane.showConfirmDialog()
메시지 - showMessageDialog()
자세한 설명은
출처 : SWING 팝업 다이얼로그 , JOptionPane, 확인 다이얼로그, 메시지 다이얼로그
에 가서 확인하기 바란다
OptionPaneEx.java
더보기
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class OptionPaneEx extends JFrame {
Container contentPane;
OptionPaneEx() {
setTitle("옵션 팬 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = getContentPane();
setSize(500, 200);
contentPane.add(new MyPanel(), BorderLayout.NORTH);
setVisible(true);
}
class MyPanel extends Panel {
JButton inputBtn = new JButton("Input Name");
JTextField tf = new JTextField(10);
JButton confirmBtn = new JButton("Confirm");
JButton messageBtn = new JButton("Message");
MyPanel() {
setBackground(Color.LIGHT_GRAY);
add(inputBtn);
add(confirmBtn);
add(messageBtn);
add(tf);
inputBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = JOptionPane.showInputDialog("이름을 입력하세요.");
if (name != null)
tf.setText(name);
}
});
confirmBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "계속할 것입니까?", "Confirm", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.CLOSED_OPTION)
tf.setText("Just Closed without Selection");
else if (result == JOptionPane.YES_OPTION)
tf.setText("Yes");
else
tf.setText("No");
}
});
messageBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "조심하세요", "Message", JOptionPane.ERROR_MESSAGE);
}
});
}
}
public static void main(String[] args) {
new OptionPaneEx();
}
}
|
cs |
반응형
'개발 실무' 카테고리의 다른 글
| [JAVA][eclipse][ERROR] eclipse PHOTON 설치 오류 (1) | 2018.09.11 |
|---|---|
| 진행바,프로그레스바(JProgressBar) (5) | 2018.09.11 |
| [JAVA][SWING] 메뉴(JMenuBar, JMenu, JMenuItem, MenuActionListener) (0) | 2018.09.11 |
| [JAVA][SWING] Drag-and-drop 파일선택시 드레그 앤 드롭 구현 (1) | 2018.09.10 |
| [JAVA][SWING]화면 중앙에 창 띄우기 (0) | 2018.09.10 |