<solved>error type mismatch

I have been working through a book on java game programing, originally written in java 1.4, but Im working in 1.6. in the original source files I downloaded the code works fine but when I moved it to 1.6 this error popped up “Type mismatch: cannot convert from Window to JFrame” what should I change to update the code? The error pops up in 2 places shown below.

JFrame frame = super.screen.getFullScreenWindow();
        Container contentPane = frame.getContentPane();

and

    public void draw(Graphics2D g) {
        super.draw(g);
        JFrame frame = super.screen.getFullScreenWindow();

Any help on updating the code would be greatly appreciated.

I usually create a JFrame via the method below :wink: don’t know any other way ::slight_smile:


String title = "Frame Title =D";
JFrame frame = new JFrame(title);

or…


JFrame frame = new JFrame("Frame Title Here? =D");

Thinking your frame.getContentPane() method will remove the error it’s giving if you fix the JFrame problem =[]

@GabrielBailey74, the OP doesn’t want to create a JFrame :wink:

@OP, screen.getFullScreenWindow() returns an object of type Window, which is a superclass of JFrame, so you can’t assign it to a JFrame. To be able to do so, you will have to cast:


JFrame frame = (JFrame)screen.getFullScreenWindow();

Only subclass types can be assigned to equal or superclass variables.

thanks that clears things up, but why did the assignment work in the original code?

It shouldn’t, unless you broke the universe (or you made that method return a JFrame at first).

Ah, he’s dealing with the 3D Universe stuff (RageQuit @ my attempts with it lul)

thats probable because now when I run the program it opens and then closed immediately and I’m not sure where to begin looking for the problem. maybe this other mystery can help you point me in the right direction?

Are there any exceptions printed in the console?

yes here they are :

Exception in thread “main” java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
at java.awt.image.BufferedImage.(BufferedImage.java:324)
at apple.awt.CGraphicsConfig.createCompatibleImage(CGraphicsConfig.java:133)
at com.brackeen.javagamebook.graphics.ScreenManager.createCompatibleImage(ScreenManager.java:251)
at MenuTest.createButton(MenuTest.java:139)
at MenuTest.init(MenuTest.java:38)
at com.brackeen.javagamebook.test.GameCore.run(GameCore.java:34)
at MenuTest.main(MenuTest.java:18)

I Hope this helps

I assume your image failed to load —> width and height are both -1 —> you create a compatible image of the same size —> ERROR! Make sure the file exists and that it’s found correctly.

thanks so much, when I copied the code over to solve my original problem I forgot to change the location of my Images in my code <>