gpt4 book ai didi

java - 消失的GUI java

转载 作者:行者123 更新时间:2023-12-02 06:29:44 25 4
gpt4 key购买 nike

我正在尝试让我的 GUI 运行它的下拉菜单

前两个选项有效,但第二个选项无效...

    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"};

关于java - 消失的GUI java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20183714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com