JOptionPane 输入对话框
有人可以教我java吗?下面的代码只是在输入对话框上使用 JOptionPane 和更多内容来获取用户数据。
概念: 第一个选项是选择交易,然后如果他们按 S,则会显示另一个输入对话框,要求输入 PIN,然后在输入 PIN 后,会显示另一个输入对话框,其中包含 4 个选项,例如提款、检查余额、存款和退出。
显示另一个输入对话框的过程是什么,然后返回到上一个输入对话框的过程是什么?那么验证用户输入以在输入错误时首先显示消息对话框然后返回到之前的输入对话框的过程是什么呢?
import javax.swing.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String myOptions = "S = Select Transaction\n"
+ "Q = Quit\n"
+ "Enter your choice";
String myPin = "Enter your PIN";
String Y = "Yes";
String N = "No";
String value = JOptionPane.showInputDialog(
null, myOptions, "Computerized Automatic Teller Machine", 1);
if (value.equals("S")) {
JOptionPane.showInputDialog(
null, myPin, "Computerized Automatic Teller Machine", 1);
} else if (value.equals("Q")) {
JOptionPane.showMessageDialog(
null, "Are you sure you want to exit?",
"Computerized Automatic Teller Machine", 1);
} else {
JOptionPane.showMessageDialog(
null, "Please the correct letter!",
"Computerized Automatic Teller Machine", 1);
JOptionPane.showInputDialog(null, myOptions,
"Computerized Automatic Teller Machine", 1);
}
}
}//end of class
Can someone enlighten me on java? The code below is just using JOptionPane and more on inputdialog box for getting data on the user.
Concept:
First option is to select transaction then if they press S another input dialog shows asking for a PIN and then after the PIN another input dialog shows with 4 options for example withdrawing,checking balance, depositing and exit.
What is the process of showing another input dialog and then what is the process of going back to previous input dialog? And then what is the process of validating user input to show a message dialog first if the input is wrong and then go back to the previous input dialog?
import javax.swing.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String myOptions = "S = Select Transaction\n"
+ "Q = Quit\n"
+ "Enter your choice";
String myPin = "Enter your PIN";
String Y = "Yes";
String N = "No";
String value = JOptionPane.showInputDialog(
null, myOptions, "Computerized Automatic Teller Machine", 1);
if (value.equals("S")) {
JOptionPane.showInputDialog(
null, myPin, "Computerized Automatic Teller Machine", 1);
} else if (value.equals("Q")) {
JOptionPane.showMessageDialog(
null, "Are you sure you want to exit?",
"Computerized Automatic Teller Machine", 1);
} else {
JOptionPane.showMessageDialog(
null, "Please the correct letter!",
"Computerized Automatic Teller Machine", 1);
JOptionPane.showInputDialog(null, myOptions,
"Computerized Automatic Teller Machine", 1);
}
}
}//end of class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,所以使用布尔值来检查是否授予访问权限。
您必须对引脚进行自己的检查,然后
将返回到循环的顶部。如果您需要我进一步澄清,请告诉我。
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
回答你的问题下面评论:
然后调用它
Ok so used a boolean to check if access is granted.
You will have to put in you own checks for the pin and the
will return to the top of the loop. Let me know if you need me to clarify further.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
In answer to your comment below :
then to call this
首先,要向多个对话框添加逻辑,您需要将它们放入 while 循环中。
其次,考虑使用一个包含所有问题的对话框。
您可以使用 JDialog 创建一个。
第三:
这里的安全是一个问题吗?您应该考虑使用代码来防止密码被窃取 - 例如 JPasswordField
Firstly, to add logic to your multiple dialog boxes, you will need to put them inside a while loop.
Secondly, consider using a single dialog with all the questions in.
You can create one by using JDialog.
Thirdly:
Is security an issue here? You should consider using code to prevent passwords from being grabbed - e.g. JPasswordField