我试着让我的GUI可以使用其下拉菜单

前2个选项起作用,但随后的2个不起作用...

    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import javax.swing.*;
    public class starter
    {
        public static void main (String [] args)
        {
            Object[] menuItems1 = {"Login as Admin", "Login as Course Leader", "Login as Lecturer", "Login as  Student", "Quit"};
            Object selectedValue1 = JOptionPane.showInputDialog(null,"Choose one",
                    "Input", 2, null, menuItems1, menuItems1[0]);
            boolean continuePlaying = true;
            if (selectedValue1 == null || selectedValue1.equals("Quit"))
                continuePlaying = false;
            else if (selectedValue1 == null || selectedValue1.equals("Login as Admin"))
            {

//this works
                adminMenu a = new adminMenu();
                a.adminMenu();
            }
            else if (selectedValue1.equals("Login as Course Leader"))
            {
//and this works
                courseLeaderMenu b = new courseLeaderMenu();
                b.courseLeaderMenu();
            }
            else if (selectedValue1.equals("Login as  Lecturer"))
            {
//but this and
                lecturerMenu c = new lecturerMenu();
                c.lecturerMenu();
            }
            else if (selectedValue1.equals("Login as Student"))
            {
// this don't
                studentMenu d = new studentMenu();
                d.studentMenu();
            }
        }
    }


任何帮助都会得到应用,这些菜单选项显然会使用我在这里调用的不同类导入其他菜单选项...一切都可以完美编译,但最后两个选项不显示任何内容

最佳答案

此if语句的字符串中有双倍空格

else if (selectedValue1.equals("Login as  Lecturer"))


并在此行的“以学生身份登录”字符串中

Object[] menuItems1 = {"Login as Admin", "Login as Course Leader", "Login as Lecturer", "Login as  Student", "Quit"};

10-06 05:37