You have to instantiate the class JFrame
and call the method setVisible(boolean b)
with the true parameter.
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
JFrame frame= new JFrame("PT Stack Overflow");
frame.setVisible(true);
}
}
If your goal is to inherit JFrame
the procedure is just that instead of instantiating JFame
you instance your heiress class of JFrame
:
import java.awt.*;
import javax.swing.*;
class MeuFrame extends JFrame
{
JLabel label;
// constructor
MeuFrame ( String titulo )
{
super( titulo ); // invoca o constructor de JFrame
setSize( 150, 100 );
// Ajusta o comportamento de fechamento do JFrame
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setLayout( new FlowLayout() );
label = new JLabel("PT Stack Overflow");
add( label ); // adiciona o JLabel ao JFrame
}
}
public class TestFrame2
{
public static void main ( String[] args )
{
MeuFrame frame = new MeuFrame("Esse é o meu frame!");
frame.setVisible( true );
}
}
That’s not how you call a window, it’s instantiating it and giving a setVisible.
– user28595
setVisible is built in the main of the window itself
– Dr.G
It depends on your application. If you’re using more than one Jframe, it’s a bad idea. The most common is Have only one Jframe, and other windows use Jdialog, and when opening Ubwindows, give a setvisible(false) in the frame to hide. That way, you don’t need to instantiate again. Don’t get me wrong, but this seems like a scam.
– user28595