Java帮助JOptionPane Madness

时间:2015-12-13 04:04:45

标签: java dropbox joptionpane

真正需要帮助的是这一直在尝试过去一小时玩耍,似乎无法得到它。已经在网上寻找了这个问题,如果有人可以帮我解决这个问题,那么获得很多类似但不完全完成任务的解决方案会很感激吗?

我目前正在开发一个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!");

1 个答案:

答案 0 :(得分:0)

字符串'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,因为程序永远不会获得该代码。