Java 帮助 JOptionPane 疯狂
Java help JOptionPane Madness
真的需要这方面的帮助,在过去的一个小时里一直在尝试,但似乎无法得到它。在网上寻找问题并获得许多类似但未完全完成任务的解决方案,如果有人可以帮助我解决这个问题,我将不胜感激?
我目前正在开发一个 dropBox API 并尝试创建一个 JOptionPane 提示用户输入从 dropBox API 生成的代码以及读取输入并验证的程序。 . 我已经成功地完成了 System.in 但这是用于 GUI 的,所以显然没有帮助。
System.out.println("Enter Your auth code in this prompt and hit enter and wait..");
String result = JOptionPane.showInputDialog(null, "Enter Code Here: ");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine();
// Want JOptionPane to function the same way this ^ would behave
String info = JOptionPane.showInputDialog(code +" test " );
if(code == null){
System.exit(1);
return;
}
code = code.trim();
// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(code);
String accessToken = authFinish.accessToken;
DbxClient client = new DbxClient(config, accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
JOptionPane.showMessageDialog(null, "Hello..."+
client.getAccountInfo().displayName+
" And Welcome To Our Community!");
字符串 'result' 应该包含他们输入到 JOptionPane 中的代码。
编辑#1:
String result = JOptionPane.showInputDialog(null, "Enter your auth code here:"); //Prompt for the auth code.
//If they didn't enter anything into the JOptionPane then close the program with code 1.
if (result.isEmpty()) {
System.exit(1);
}
System.out.println(result.trim()); //For testing purposes print the trimmed auth code to console.
// [Omitted Code] //
此外,您不需要在 System.exit(#) 之后调用 return,因为程序无论如何都不会到达该代码。
真的需要这方面的帮助,在过去的一个小时里一直在尝试,但似乎无法得到它。在网上寻找问题并获得许多类似但未完全完成任务的解决方案,如果有人可以帮助我解决这个问题,我将不胜感激?
我目前正在开发一个 dropBox API 并尝试创建一个 JOptionPane 提示用户输入从 dropBox API 生成的代码以及读取输入并验证的程序。 . 我已经成功地完成了 System.in 但这是用于 GUI 的,所以显然没有帮助。
System.out.println("Enter Your auth code in this prompt and hit enter and wait..");
String result = JOptionPane.showInputDialog(null, "Enter Code Here: ");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine();
// Want JOptionPane to function the same way this ^ would behave
String info = JOptionPane.showInputDialog(code +" test " );
if(code == null){
System.exit(1);
return;
}
code = code.trim();
// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(code);
String accessToken = authFinish.accessToken;
DbxClient client = new DbxClient(config, accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
JOptionPane.showMessageDialog(null, "Hello..."+
client.getAccountInfo().displayName+
" And Welcome To Our Community!");
字符串 'result' 应该包含他们输入到 JOptionPane 中的代码。
编辑#1:
String result = JOptionPane.showInputDialog(null, "Enter your auth code here:"); //Prompt for the auth code.
//If they didn't enter anything into the JOptionPane then close the program with code 1.
if (result.isEmpty()) {
System.exit(1);
}
System.out.println(result.trim()); //For testing purposes print the trimmed auth code to console.
// [Omitted Code] //
此外,您不需要在 System.exit(#) 之后调用 return,因为程序无论如何都不会到达该代码。