消失的GUI java

时间:2013-11-25 02:01:38

标签: java swing user-interface

我试着让我的GUI工作一个下拉菜单

前两个选项有效但第二个有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();
            }
        }
    }

任何帮助都会受到影响,这些菜单选项会导致其他显然使用我在这里调用的不同类...其他所有内容编译完美但最后2个选项不显示任何内容

1 个答案:

答案 0 :(得分:2)

此if语句

中的字符串中有两个空格
else if (selectedValue1.equals("Login as  Lecturer"))

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

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