如何使用 JOptionPane return 到上一帧?
How to return to the previous frame with JOption Pane?
所以我正在为学校做一个项目,我在其中创建了一个数据库,其中包含元素周期表中所有化学物质的信息,并且在运行该程序时,系统会提示用户在几个之间进行选择选项,例如搜索、排序等。像这样:
String[] options = new String[] {"Search", "Sort", "Add", "Delete", "Exit"};
int x=JOptionPane.showOptionDialog(null, "Choose one of the following:", "Virtual Periodic Table", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
while (true)
{
if (options[x]=="Search")
{
searchMenu();
}
else if (options[x]=="Sort")
{
}
else if (options[x]=="Add")
{
}
else if (options[x]=="Delete")
{
}
else if (options[x]=="Exit")
{
break;
}
}
我还没有完全完成,截至目前我仍在研究搜索选项。无论如何,在单击搜索选项后,我调用了一个弹出另一个菜单的过程,该菜单提示用户指定他们想要搜索的内容,如下所示:
String[] options = new String[] {"Name", "Symbol", "Atomic Number", "Atomic Mass", "# of Valence Electrons", "Go Back"};
int x=JOptionPane.showOptionDialog(null, "What would you like to search by?", "Virtual Periodic Table", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
if (options[x]=="Name")
{
searchByName();
}
else if (options[x]=="Symbol")
{
}
else if (options[x]=="Atomic Number")
{
}
else if (options[x]=="Atomic Mass")
{
}
else if (options[x]=="# of Valence Electrons")
{
}
else if (options[x]=="Go Back")
{
}
现在,我正在尝试找出一种方法,让用户可以选择返回主菜单,以便他们可以对数据执行其他操作。例如,如果我决定搜索,但后来又决定实际排序,我可以简单地按 "Go Back",它会弹出上一个菜单,这是主菜单,所以我可以选择下一步我想做什么.我已经添加了显示 "Go Back" 的按钮,但我不太确定如何制作它所以它实际上将命令返回给可以再次弹出主菜单的主要方法。我试图将搜索菜单置于一个 while 循环中,然后在他们单击 "Go Back" 时使其跳出循环,但它除了关闭整个程序外什么也没做。
我对 Java 中的 GUI 还是很陌生,有人知道我能做什么吗?
您必须将 ShowOptionDialog 放在 while 循环中,以便在您离开搜索菜单时再次调用它
所以我正在为学校做一个项目,我在其中创建了一个数据库,其中包含元素周期表中所有化学物质的信息,并且在运行该程序时,系统会提示用户在几个之间进行选择选项,例如搜索、排序等。像这样:
String[] options = new String[] {"Search", "Sort", "Add", "Delete", "Exit"};
int x=JOptionPane.showOptionDialog(null, "Choose one of the following:", "Virtual Periodic Table", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
while (true)
{
if (options[x]=="Search")
{
searchMenu();
}
else if (options[x]=="Sort")
{
}
else if (options[x]=="Add")
{
}
else if (options[x]=="Delete")
{
}
else if (options[x]=="Exit")
{
break;
}
}
我还没有完全完成,截至目前我仍在研究搜索选项。无论如何,在单击搜索选项后,我调用了一个弹出另一个菜单的过程,该菜单提示用户指定他们想要搜索的内容,如下所示:
String[] options = new String[] {"Name", "Symbol", "Atomic Number", "Atomic Mass", "# of Valence Electrons", "Go Back"};
int x=JOptionPane.showOptionDialog(null, "What would you like to search by?", "Virtual Periodic Table", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
if (options[x]=="Name")
{
searchByName();
}
else if (options[x]=="Symbol")
{
}
else if (options[x]=="Atomic Number")
{
}
else if (options[x]=="Atomic Mass")
{
}
else if (options[x]=="# of Valence Electrons")
{
}
else if (options[x]=="Go Back")
{
}
现在,我正在尝试找出一种方法,让用户可以选择返回主菜单,以便他们可以对数据执行其他操作。例如,如果我决定搜索,但后来又决定实际排序,我可以简单地按 "Go Back",它会弹出上一个菜单,这是主菜单,所以我可以选择下一步我想做什么.我已经添加了显示 "Go Back" 的按钮,但我不太确定如何制作它所以它实际上将命令返回给可以再次弹出主菜单的主要方法。我试图将搜索菜单置于一个 while 循环中,然后在他们单击 "Go Back" 时使其跳出循环,但它除了关闭整个程序外什么也没做。
我对 Java 中的 GUI 还是很陌生,有人知道我能做什么吗?
您必须将 ShowOptionDialog 放在 while 循环中,以便在您离开搜索菜单时再次调用它