Search code examples
javastringif-statementjoptionpane

Calling a class from within a class


String ans = JOptionPane.showInputDialog(null, "S,T,R,K or P?");
if (ans == "S")
{ 
    class Square
}

Basically, I'd like to run this exert of code under a main class Shapes, and then in the if statement I'd like to know how to run another separate class inside this class Shapes if possible, i.e.

ans = S

and then it runs another program which creates a square using text stars "*" in that same Shapes program.


Solution

  • If coded correctly then what your asking to do in your question would be able to work just fine!

    String ans = JOptionPane.showInputDialog(null, "S,T,R,K or P?");
    if (ans.equals("S"))
    { 
        Square s = new Square();
    }
    

    Square Class

    public class Square {
    //bla bla bla
    }