자바의 JOptionPane 클래스는 입력과 출력을 위해 미리 패키지화되어 있는 다이얼로그 박스를 제공한다. 이러한 디얼로그들은 JOptionPane 클래스에 정의되어 있는 static 메소드를 호출함으로써 화면에 나타난다.
JOptionPane의 다이얼로그 종류
| 메소드명 | 설명 |
|---|---|
| showConfirmDialog | yes/no/cancel 등의 확인의 요구 |
| showInputDialog | 입력 prompt |
| showMessageDialog | 발생했던 것에 대한 사용자에게로의 메세지 |
| showOptionDialog | 이상의 3 개를 맞춘 것 |
import javax.swing.JOptionPane;
public class Addition {
public static void main(String[] args) {
String firstNumber=JOptionPane.showInputDialog("Enter first number");
String secondNumber=JOptionPane.showInputDialog("Enter second number");
int number1=Integer.parseInt(firstNumber);
int number2=Integer.parseInt(secondNumber);
int sum=number1+number2;
JOptionPane.showMessageDialog(null, "The sum is " + sum, "Sum of Tow Intergers", JOptionPane.PLAIN_MESSAGE);
}
}'Developer > Java' 카테고리의 다른 글
| Swing vs AWT (0) | 2012.08.22 |
|---|---|
| HashMap value를 정렬하는 방법 (0) | 2012.07.18 |
| 배열의 복사 (0) | 2012.07.04 |
| 클래스변수, 클래스메서드 (0) | 2012.07.04 |
| Java의 기본 (0) | 2012.07.04 |



