Java JOptionPane到JFrame

时间:2014-03-26 14:15:14

标签: java jframe joptionpane

我是java的新手,想知道他们是否可以从JOptionFrame跳转到JFrame 到目前为止,这是我的代码:

public class Input {

 public static void main(String[] args) {
String choose;


choose = JOptionPane.showInputDialog("Create New\n 1. Customer\n 2. Invoice");

if(choose.equalsIgnoreCase("customer")|| choose =="1"){


}else if(choose.equalsIgnoreCase("invoice")|| choose =="2"){


}else return;

 } 
}

2 个答案:

答案 0 :(得分:0)

使用equals()代替==

if (choose.equalsIgnoreCase("customer")||choose.equals("1")) {
        /// call customer JFrame here 
 } else if (choose.equalsIgnoreCase("invoice")||choose.equals("2")) {
        /// call invoice JFrame here 
 } 

答案 1 :(得分:0)

不要使用==比较字符串,使用.equals(),也要显示您想要的JFrame 假设您有一个CustomerJFrame扩展JFrame 你需要做的事:

if(choose.equalsIgnoreCase("customer") || choose.equals("1")){
    JFrame customerFrame = new CustomerJFrame();
    customerFrame.setVisible(true); // here how show your jframe.
}