I was just goofing around with java when i thought of trying to get my work done not from a method but from a class. Check out what I did.
import javax.swing.*;
class foolingAround{
public static void main(String ARG[]) {
createMyInterface();
}
private static void createMyInterface(){
JFrame f = new JFrame("Frame from Swing but not from other class");
f.setSize(100,100);
f.setVisible(true);
new createAnotherInterface();
}
}
class createAnotherInterface{
public static void main(String arg[]){
giveMe();
}
static JFrame giveMe(){
JFrame p = new JFrame("Frame from Swing and from another class");
p.setSize(100,100);
p.setVisible(true);
return p;
}
}
It compiled without showing any error but the frame from class createAnotherInterface did not show up. Why? When do i make different classes and not methods?
You were just creating a new Object for createAnotherInterface class and by default it calls its default constructor and in that default constructor there is no call to giveMe() method.
I am not sure if i am right or wrong but i ask you to create a constructor in “createAnotherInterface” class and call the “giveMe()” method in the constuctor. i hope that will solve your problem.
or atleast call
in your createMyInterface() class