java - 如何将 "translate"此扫描仪输入到 JOptionPane showOptionDialog

标签 java swing joptionpane

我正在努力使我的代码更加用户友好。我有这部分代码,想知道如何将它转换为 joptionpane。 我找到了这个 int result = JOptionPane.showConfirmDialog(frame, "Continue printing?"); 但使用另一个 jframe 似乎有点奇怪。

System.out.println("Make more selections? Type Yes or No");

Scanner scanre = new Scanner( System.in );
String selecend;
selecend = scanre.next();
if(selecend.equalsIgnoreCase("Yes")) {
    System.out.println("Enter next selection: ");
    query();
};      

最佳答案

more user friendly

接下来呢?

private Something showMessage() {

    // null for 'console' mode or this if the enclosing type is a frame
    Component parentComponent = null; 
    Object message = "Make more selections?";
    String title = "Message";
    int optionType = JOptionPane.YES_NO_OPTION; // 2 buttons
    int messageType = JOptionPane.QUESTION_MESSAGE; // icon from style
    Icon icon = null;

    // String in the buttons!
    Object[] options = { "Yup!", "Nope!" };

    // option saves the index 'clicked'
    int option = JOptionPane.showOptionDialog(
            parentComponent, message, title, 
            optionType, messageType, icon,
            options, options[0]);

    switch (option) {
    case 0:
        // button with "Yup!"
        break;
    case 1:
        // button with "Nope!"
        break;
    default:
        // you close the dialog or press 'escape'
        break;
    }

    return Something;
}

enter image description here

关于java - 如何将 "translate"此扫描仪输入到 JOptionPane showOptionDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19186721/

相关文章:

java - 从 spring application.yml 文件中读取 env 变量以在 Cloud Foundry 上部署应用程序

java - 检测 java.lang.Class.getResourceAsStream() 打开的目录

绘制列表时发生 Java 错误

java - myBatis 中的循环引用

java - Swing JScrollPane 更新时重置滚动位置

java - JTextPane 换行行为

Java:如何从 JButton 打开 JOptionPane

java - 为什么单击按钮后我的程序会给出错误的输出?

java - ImageIcon 无法更改默认的 JOptionPane 图标

java - Tomcat:在哪里可以找到 Tomcat Lib 文件夹