共計 487 個字符,預(yù)計需要花費 2 分鐘才能閱讀完成。
在 Java 中,你可以使用 JOptionPane 類中的 showInputDialog() 方法來創(chuàng)建一個對話框。
以下是一個簡單的示例:
import javax.swing.JOptionPane;
public class DialogExample {public static void main(String[] args) {// 顯示一個輸入對話框
String input = JOptionPane.showInputDialog(" 請輸入一個值:");
// 打印用戶輸入的值
System.out.println(" 你輸入的值是:" + input);
// 顯示一個消息對話框
JOptionPane.showMessageDialog(null, " 操作成功!");
}
}
這個示例中,先使用 showInputDialog() 方法創(chuàng)建一個輸入對話框,用戶可以在對話框中輸入一個值。然后,使用 showMessageDialog() 方法創(chuàng)建一個消息對話框,顯示一個成功的消息。
注意:在使用 JOptionPane 類之前,你需要導(dǎo)入 javax.swing.JOptionPane 類。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完