Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  ClassCastException and BufferStrategy  (Read 1014 times)
0 Members and 1 Guest are viewing this topic.
Offline antisocial

Junior Newbie




Java games rock!


« Posted 2005-03-14 00:40:06 »

I just want to draw a black window! (sob.)

I was messing around with kevglass' space invaders tutorial, but couldn't get anything to draw to the window, due to the following exception:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Exception in thread "main" java.lang.ClassCastException
   at apple.awt.StrategyBufferImage.<init>(StrategyBufferImage.java:26)
        at apple.awt.ContainerModel.createBuffers(ContainerModel.java:155)
        at java.awt.Component$FlipBufferStrategy.createBuffers(Component.java:3111)
        at java.awt.Component$FlipBufferStrategy.<init>(Component.java:3080)
        at java.awt.Component.createBufferStrategy(Component.java:2989)
        at java.awt.Canvas.createBufferStrategy(Canvas.java:166)
        at java.awt.Component.createBufferStrategy(Component.java:2921)
        at java.awt.Canvas.createBufferStrategy(Canvas.java:141)
        at Game.<init>(Game.java:25)
        at Game.main(Game.java:42)

I'm new to this, so I wouldn't be surprised if it were due to some silly oversight on my part. Any suggestions, corrections or workarounds would be greatly appreciated. I tried to simplify as much as possible for troubleshooting purposes. Here's the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

public class Game extends Canvas {

      private boolean gameRunning = true;

      public Game() {
            JFrame container = new JFrame("Black Rectangle");
            JPanel panel = (JPanel) container.getContentPane();
            panel.setPreferredSize(new Dimension(800,600));
            panel.setLayout(null);
           
            setBounds(0,0,800,600);
            panel.add(this);
           
            setIgnoreRepaint(true);
           
            container.pack();
            container.setResizable(false);
            container.setVisible(true);
            requestFocus();
           
            createBufferStrategy(2);
            BufferStrategy strategy = getBufferStrategy();
     
            while (gameRunning) {
                 
                  Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
                  g.setColor(Color.black);
                  g.fillRect(0,0,800,600);
           
                  g.dispose();
                  strategy.show();
                 
                  try { Thread.sleep(10); } catch (Exception e) {}
            }
      }

      public static void main(String args[]) {
            new Game();
      }
     
}

I mean, this should work, right?

I'm running Mac OS X 10.3.8 with Java 1.42 and an nVidia GeForce FX 5200 video card.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #1 - Posted 2005-03-14 10:29:55 »

Definitely something strange going on.  I copied the code exactly and it works fine for me.

Offline digitprop

Junior Member





« Reply #2 - Posted 2005-03-14 10:40:25 »

I may have overlooked something (a speciality of mine), but it seems ok to me.

Could be an Apple-specific problem. It compiles and runs fine on my system (Windows XP, Java 1.4.2).

M. Fischer . www.digitprop.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline antisocial

Junior Newbie




Java games rock!


« Reply #3 - Posted 2005-03-15 03:56:21 »

Well, good and bad news.

Bad: The problem definitely seems to be a problem with Apple's implementation of BufferStrategy.

Good: It seems to work fine when I use the BufferStrategy with a Frame instead of a subclass of Canvas.

Not an ideal fix to the problem, but I guess it will have to do.

Edit: Crap. That means I can't use accelerated graphics, doesn't it?
Crap.
Offline Valodim

Junior Member




*sigh*


« Reply #4 - Posted 2005-03-15 19:05:30 »

what? bufferstrategy from a frame can't be accelerated? Shocked
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2005-03-21 10:51:13 »

This has nothing to do with hardware acceleration - which is not implemented AT ALL on the Mac for Java 1.4.2.

It seems to be a quirk in the Apple implementation of BufferStrategies... perhaps a bug should be filed with Apple.

Thankfully, according to rumors, we are not far away from the release of Mac OS X 10.4, and with it Java 5 for the Mac, with faster graphics and nice stuff like that.

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.

E.R. Fleming (20 views)
2014-07-29 03:07:13

E.R. Fleming (7 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (45 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!