2014-03-26 40 views
0

我是新来的Java,想知道他们是否是跳转到一个JFrame从JOptionFrame 这是到目前为止我的代码的方式:的Java的JOptionPane到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

请问你能详细解释一下你跳什么意思?并且不要对字符串使用'=='。检查此链接:http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java –

回答

0

不要使用==比较字符串,使用.equals(),也表明你想要JFrame假设你有一个CustomerJFrame延伸的JFrame你需要做的:

if(choose.equalsIgnoreCase("customer") || choose.equals("1")){ 
    JFrame customerFrame = new CustomerJFrame(); 
    customerFrame.setVisible(true); // here how show your jframe. 
} 
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 
}