java - 运行程序并输入正确的输入后,程序不会显示程序的答案

标签 java joptionpane

所以我有我的程序,它只是在最后一个问题(需要输入)之后不会运行。我的代码在这里:

import java.util.Scanner;

import javax.swing.JOptionPane;

public class HiConor
{

   public static void main(String[] args)
   {

      String result; 
      int selection;
      int Entry;
      boolean isYes;
      System.out.print("Starting Program");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      JOptionPane.showMessageDialog(null, "Hello there!");
      selection = JOptionPane.showConfirmDialog(null, "Are you doing good?");
      boolean isNo;
      boolean isCancel;
      isNo = (selection == JOptionPane.NO_OPTION);
      isYes = (selection == JOptionPane.YES_OPTION);
      isCancel = (selection == JOptionPane.CANCEL_OPTION);
      if(isYes){
      JOptionPane.showMessageDialog(null, "Yes?" + " That's nice to hear!");
         } 
      if(isNo){
      JOptionPane.showMessageDialog(null, "No?" + " Well then, cheer up!");
         } 
      if(isCancel){
      JOptionPane.showMessageDialog(null, "Fine then, don't respond");
         }   
      Scanner keyBoard = new Scanner(System.in);
      Scanner input = new Scanner(System.in);
      JOptionPane.showInputDialog(null, "What is your name?",
      "Mlg recess poofs",
      JOptionPane.ERROR_MESSAGE);
      String userinput = input.next();
      if(userinput.equals("alex")){
         JOptionPane.showMessageDialog(null, "What a lovely name!");
         }

      JOptionPane.showMessageDialog(null, "I have a feeling you're trolling me " + ". This is the end of the program. Goodbye.");
      }}

最佳答案

改成这样

String userinput =  JOptionPane.showInputDialog(null, "What is your name?",
      "Mlg recess poofs",
      JOptionPane.ERROR_MESSAGE);

删除:

Scanner input = new Scanner(System.in);
String userinput = input.next();

关于java - 运行程序并输入正确的输入后,程序不会显示程序的答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576773/

相关文章:

java - 复杂字符串数据提取

java - Play Framework : How to share models between different projects?

java - 如果需要多次访问数组元素,如何减少对数组的搜索?

java - JCheckBox 状态在类之间保持一致

java - 在服务器端向用户显示问题 [Java]

java - 我将如何通过 JOptionpanes 添加到我的数组?

java - 安卓/Java : Problem with sending param and receiving JSON response with RetroFit in POST

java - 如何在android中从firebase实时数据库获取数据

java - 更改 JOptionPane 中的 OK Cancel 字符串

java - JFrame 的内容不显示