gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:54:01 30 4
gpt4 key购买 nike

我正在努力使我的代码更加用户友好。我有这部分代码,想知道如何将它转换为 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com