什么都没发生?简单的代码和新的编码器?

时间:2015-01-08 21:57:42

标签: java joptionpane

我正在使用BlueJ。我也在导入javax.swing。*并尝试为学校创建一个快速系统,用户输入一个名为" Genre"如果它是幻想,那就会出现哈利波特,饥饿游戏等阵容。它不起作用:/

public class Project
{
    /**
    * Constructor for objects of class Project
    */
    public static void main(String args[])
    {
        String Input;
        String[] books = new String[5];
        books[0]= "Harry Potter Series: 1\n";
        books[1]= "The Lion, the Witch, and the Wardrobe: 2\n";
        books[2]= "Lord of The Rings Series: 3\n";
        books[3]= "The Hunger Games: 4\n";
        books[4]= "Ender's Game: 5\n";
        String Genre, summary; 
        Genre = JOptionPane.showInputDialog(null, 
        "Enter Genre:", "Genre",
        JOptionPane.QUESTION_MESSAGE);

        //I think something is wrong with the following line:
        if (Genre =="Fantasy")
        {
            JOptionPane.showMessageDialog(null,
            "Type the corresponding number to the book/series\n you would like information on:\n\n" +
            books[0] +
            books[1]+
            books[2]+
            books[3]+
            books[4], "Fantasy Books",
            JOptionPane.INFORMATION_MESSAGE);
        }
        System.exit(0);
    }
}

1 个答案:

答案 0 :(得分:1)

试试这个

public class Project
{

    public static void main(String args[])
    {
        String Input;
        String[] books = new String[5];
        books[0]= "Harry Potter Series: 1\n";
        books[1]= "The Lion, the Witch, and the Wardrobe: 2\n";
        books[2]= "Lord of The Rings Series: 3\n";
        books[3]= "The Hunger Games: 4\n";
        books[4]= "Ender's Game: 5\n";
            String Genre, summary; 
            Genre = JOptionPane.showInputDialog(null, "Enter Genre:", "Genre",
            JOptionPane.QUESTION_MESSAGE);
            String ab= "Fantasy";

            if (Genre.equals(ab))
            {
            JOptionPane.showMessageDialog(null,
            "Type the corresponding number to the book/series\n you would like information on:\n\n" +
            books[0] +
            books[1]+
            books[2]+
            books[3]+
            books[4], "Fantasy Books",
            JOptionPane.INFORMATION_MESSAGE);
        }
               System.out.println("error");

            }
        }