I want to create a JFrame
with a JLabel
on it reading "Simple Text". But not in the usual way. I want to do it in such a way that JFrame
stands alone as one class in one tab, and the Jlabel in another tab. How can I do it? I did it as shown below, but the text didn’t appear on the window.
public class FirstClass {
public static void main (String [] args) {
SecondClass sc = new SecondClass ();
ThirdClass tc = new ThirdClass ();
sc.newWindow ();
tc.newText ();
}
}
import javax.swing.JFrame;
public class SecondClass {
public void newWindow () {
JFrame jf = new JFrame ("Text Window");
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(500, 500);
}
}
import javax.swing.JLabel;
public class ThirdClass {
public void newText (){
JLabel jl = new JLabel ("Simple Text");
jl.setVisible(true);
jl.setBounds(50, 50, 50, 50);
add (jl);
}
}