Reputation: 83
I know that this question was asked many times and I've tried solutions mentioned there for last hour, but none of them worked for me. I have very basic frame and it just doesn't show up. No errors, after compilation just "Build succesful".
The whole code is:
import javax.swing.*;
import java.awt.*;
public class Frame extends JFrame
{
public Frame()
{
super("Hello");
this.setBounds(100, 500, 100, 100);
this.setDefaultCloseOperation(3);
}
public static void main(String[] args)
{
new Frame().setVisible(true);
}
}
Thanks in advance for your help.
Upvotes: 0
Views: 1472
Reputation: 324088
Start by reading the Swing tutorial on How to Make Frames.
Download and test the FrameDemo example. It show you the proper way to create Swing components. One key is that Swing components should be created on modified on the Event Dispatch Thread (EDT).
If this code doesn't work then you probably have something wrong with your JDK. Try reinstalling.
Upvotes: 1
Reputation: 394
I tried your program and the frame shows up fine for me. Couple of steps which you can try -
this.pack();
after this.setDefaultCloseOperation
and re-run the program.Upvotes: 1
Reputation: 273
I think your Frame instance in main is from package java.awt.* which you have imported. Check it out.
Upvotes: 1