JFrame to Window Class

I want to know which of these lines is he really right, or is there a better way? can someone help me?

JFrame jframe=new JFrame()
Window window;
jframe.setUndecorated(true);


window=(Window)jframe; //is this line true?

thank.

+3
source share
2 answers

Yes, that’s true, but you don’t need a throw. java.swing.JFrame is a child of the java.awt.Window class, so this is normal. And I can’t find the reason the method applied to your Window variable is not applicable to the JFrame variable. This should not happen because Java uses only late bindings for method calls.

Try looking at your code to see if you are importing the classes you need, because I think you are misunderstanding something.

+2
source

JFrame, - . , createAndShowGUI():

public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
        try {
            createAndShowGUI();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        }
    });
    }

JFrame:

static void createAndShowGUI() throws UnsupportedLookAndFeelException {
    // Creates the window (JFrame)
    frame = new JFrame("Name of the window");//                                    
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    new Interface();
    frame.pack();
    frame.setSize(700, 400);
    frame.setLocationRelativeTo(null);// centers the window in the screen
    frame.setVisible(true);
    }

() , JPanels , .

, , ? , Swing.

+2

All Articles