2014-03-26 41 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 
}