티스토리 뷰

Studying/JAVA

MessageBox 소스

hongkyu 2011. 4. 20. 13:47


출처 : http://www.java-forums.org/java-tips/6578-messagebox-example.html

public class MessageBox {
    /*
    These are a list of STATIC MODAL dialogs
    int return codes of button pressed:

        -1 - WINDOW CLOSED - the X PRESSED
         0 - YES and OK
         1 - NO
         2 - CANCEL

    (thanks to flipside for the idea)
     */

    public static int yesno(String theMessage){
        int result = JOptionPane.showConfirmDialog((Component)
                null, theMessage, "alert", JOptionPane.YES_NO_OPTION);
        return result;
    }

    public static int yesnocancel(String theMessage){
        int result = JOptionPane.showConfirmDialog((Component)
                null, theMessage, "alert", JOptionPane.YES_NO_CANCEL_OPTION);
        return result;
    }

    public static int okcancel(String theMessage){
        int result = JOptionPane.showConfirmDialog((Component)
                null, theMessage, "alert", JOptionPane.OK_CANCEL_OPTION);
        return result;
    }

    public static int ok(String theMessage){
        int result = JOptionPane.showConfirmDialog((Component)
                null, theMessage, "alert", JOptionPane.DEFAULT_OPTION);
        return result;
    }

    public static void main(String args[]){
        int i = MessageBox.yesno("Are your sure ?");
        System.out.println("ret : " + i );
        i = MessageBox.yesnocancel("Are your sure ?");
        System.out.println("ret : " + i );
        i = MessageBox.okcancel("Are your sure ?");
        System.out.println("ret : " + i );
        i = MessageBox.ok("Done.");
        System.out.println("ret : " + i );
    }
}

반응형

'Studying > JAVA' 카테고리의 다른 글

클래스 설계 기법  (0) 2011.03.28
BlueCove stack  (0) 2011.03.28
외부 라이브러리를 포함한 Jar 파일 만들기  (0) 2011.03.28
Singleton (싱글톤) 패턴  (0) 2011.03.24
현재 마우스 포인트 위치 구하기  (0) 2011.03.24
댓글
«   2024/05   »
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
최근에 올라온 글
글 보관함
Total
Today
Yesterday