Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  <solved>error type mismatch  (Read 1803 times)
0 Members and 1 Guest are viewing this topic.
Offline darkjava55

Senior Newbie





« Posted 2012-05-26 23:00:27 »

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.

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


and

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

Any help on updating the code would be greatly appreciated.

Offline GabrielBailey74
« Reply #1 - Posted 2012-05-26 23:05:02 »

I usually create a JFrame via the method below Wink don't know any other way  Roll Eyes

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


or..

1  
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 =[]

Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2012-05-26 23:08:15 »

@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:
1  
JFrame frame = (JFrame)screen.getFullScreenWindow();


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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkjava55

Senior Newbie





« Reply #3 - Posted 2012-05-26 23:26:15 »

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

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2012-05-26 23:35:35 »

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

Offline GabrielBailey74
« Reply #5 - Posted 2012-05-26 23:37:21 »

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

Offline darkjava55

Senior Newbie





« Reply #6 - Posted 2012-05-26 23:40:36 »

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?
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-05-26 23:48:09 »

Are there any exceptions printed in the console?

Offline darkjava55

Senior Newbie





« Reply #8 - Posted 2012-05-26 23:51:13 »

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.<init>(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
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #9 - Posted 2012-05-26 23:55:53 »

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.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkjava55

Senior Newbie





« Reply #10 - Posted 2012-05-27 00:16:54 »

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 <<facepalm>>
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!