Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 1128 times)
0 Members and 1 Guest are viewing this topic.
Offline darkjava55

Senior Newbie





« Posted 2012-05-27 01: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

JGO Knight


Medals: 8
Projects: 6


<3 Java


« Reply #1 - Posted 2012-05-27 01: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 =[]

Online ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #2 - Posted 2012-05-27 01: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!
Try the Free Demo of Droid Assault
Offline darkjava55

Senior Newbie





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

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

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #4 - Posted 2012-05-27 01:35:35 »

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

Offline GabrielBailey74

JGO Knight


Medals: 8
Projects: 6


<3 Java


« Reply #5 - Posted 2012-05-27 01: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-27 01: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?
Online ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #7 - Posted 2012-05-27 01:48:09 »

Are there any exceptions printed in the console?

Offline darkjava55

Senior Newbie





« Reply #8 - Posted 2012-05-27 01: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
« Reply #9 - Posted 2012-05-27 01: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!
Try the Free Demo of Revenge of the Titans
Offline darkjava55

Senior Newbie





« Reply #10 - Posted 2012-05-27 02: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.08 seconds with 21 queries.