[英]How to make a certain window pop up if a certain number is put in
I was wondering how do i make a certain window pop up if I input a certain number for my java program. 我想知道如果我为Java程序输入特定的数字,如何弹出特定的窗口。
import javax.swing.JOptionPane;
public class Calculator_Menu
{
public static void main (String args [])
{
String MainMenu = " Calculator Options \n\n1. Addition\n2" +
" Subtraction\n3. Multiplication\n4. Division\n5. Exit";
menu (MainMenu);
}
public static String menu (String info)
{
String choice = JOptionPane.showInputDialog (info);
return choice;
}
public static int Addition ()
{
If you are looking to just have a window pop up to display the number, you could use something like showMessageDialog
with an if statement - 如果您只是想弹出一个窗口来显示数字,则可以使用带if语句的
showMessageDialog
东西-
Code: 码:
if (choice == desiredNumber) {
JOptionPane.showMessageDialog(null,choice);
}
You need to import javax.swing.JOptionPane
for this to work. 您需要导入
javax.swing.JOptionPane
才能使其工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.