Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: ClassCastException and BufferStrategy on: 2005-03-15 02: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.
2  Game Development / Newbie & Debugging Questions / ClassCastException and BufferStrategy on: 2005-03-13 23: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.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (67 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!