2011-06-07 104 views

回答

40

請參閱How to Make Dialogs

您可以使用:

JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green."); 

而且你還可以更改符號的錯誤消息或警告。例如參見JOptionPane Features

+0

確保你處置框架,或傳遞null作爲框架。如果你不這樣做,它可以保持你的過程開放。 – ScrappyDev 2017-02-24 15:47:16

9
JOptionPane.showOptionDialog 
JOptionPane.showMessageDialog 
.... 

看看這個tutorial關於如何進行對話。

+0

謝謝,這個工程 – javapowered 2011-06-07 19:20:43

11
import javax.swing.JFrame; 
import javax.swing.JOptionPane; 

public class ErrorDialog { 

    public static void main(String argv[]) { 
    String message = "\"The Comedy of Errors\"\n" 
     + "is considered by many scholars to be\n" 
     + "the first play Shakespeare wrote"; 
    JOptionPane.showMessageDialog(new JFrame(), message, "Dialog", 
     JOptionPane.ERROR_MESSAGE); 
    } 
} 
0

只是補充:這是一種顯而易見的,但你可以使用靜態導入給你一隻手,像這樣:

import static javax.swing.JOptionPane.*; 

public class SimpleDialog(){ 
    public static void main(String argv[]) { 
     showMessageDialog(null, "Message", "Title", ERROR_MESSAGE); 
    } 
}