[Solved] Java Switch not working like expected


you’re missing the break statement

switch (c_a.getText()) {
    case "Customer": {
        new LoginPage().setVisible(true);
        break;
    }
    case "Admin": {
        new LoginPageadmin().setVisible(true);
        break;
    }
    default: {
        JOptionPane.showMessageDialog(this, "Please try again");
        break;
    }
}

source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

solved Java Switch not working like expected