Question

I am new to java and wanted to know if they was a way to jump to a JFrame from a JOptionFrame this is my code so far:

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;

 } 
}
Was it helpful?

Solution

Don't use == to compare String, use .equals(), also to show the JFrame you want suppose that you have a CustomerJFrame extends JFrame you need to do:

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

OTHER TIPS

Use equals() instead of ==

if (choose.equalsIgnoreCase("customer")||choose.equals("1")) {
        /// call customer JFrame here 
 } else if (choose.equalsIgnoreCase("invoice")||choose.equals("2")) {
        /// call invoice JFrame here 
 } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top