public class Main extends JFrame{
JLabel lb1,lb2,lb3,lb4;
Button b,b1;
public Main()
{
setLayout(null);
Container c=getContentPane();
setDefaultCloseOpe
Swing does it's GUI rendering task inside a single thread known as Event Dispatch Thread(EDT)
. Any thing you do which might take a while will block the EDT and your swing application will be frozen. You are doing such thing by one of your statement:
Thread.sleep(5000);
This is always suggested not to work with NullLayout
. Learn proper layout mangers that Swing developer has created for us with their hard work. Let us give some value to their effort.
Put your GUI rendering task including frame
's setVisible(true)
inside EDT by using SwingUtilities.invokeLater
function. For example:
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MyWindow().setVisible(true);
}
});
You are working with Multiple Frame. It is also prohibited by the Swing family of Stack Overflow. There are lots of work around shown using Card Layout
by the family which you can easily adopt for avoiding use of multiple frame unnecessarily. Some example are given in the answer of Andrew Thompson
with given link.