• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have a small buffering issue.  RSS feed

 
Joseph Alrawi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!

Honestly I'm looking up online for fundamentals on how to make a game, I'm trying to understand what I'm doing, but it seems like I messed up my code a little. All I want to do is buffer black and white stripes onto a window, the point is that it is going to display first a white stripe and wait, then black and wait, then white and wait etc etc.



From what I've read g.dispose rids all the graphic resources, so these graphics rely only on java. Second is that bs.show simply shows the buffered image. I've set how many times the program buffers images to 3. So the issue is that the black and white just appears a little here and there in my window, but still in a pattern. How did I mess up my pattern? Because I can't figure out what's wrong with it.

Edit: I tried out calling g.dispose inside the loop as well, but if I do that it only displays black then white, then black then white etc etc. No stripes at all, how come?

It's still a nice start for me considering it's my first time trying this out.

Thanks for your time!
 
Knute Snortum
Sheriff
Posts: 3556
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you haven't gotten a response yet, I would suggest posting a complete program, as small as possible, that demonstrates the problem. Sometimes just doing this will make the bug clear.

If the program is too big to put into a message, use Google Drive or Dropbox to upload the file and post the link.
 
Joseph Alrawi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Since you haven't gotten a response yet, I would suggest posting a complete program, as small as possible, that demonstrates the problem. Sometimes just doing this will make the bug clear.

If the program is too big to put into a message, use Google Drive or Dropbox to upload the file and post the link.


Thanks for the suggestion, I posted the entire code.
 
Tony Docherty
Bartender
Posts: 3209
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The posted code works on my system.

One thing I immediately noticed about your code is you are mixing AWT and Swing components which can cause problems on some versions of Java. I suggest you change JFrame to Frame and see if it works on your system.
 
Joseph Alrawi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:The posted code works on my system.

One thing I immediately noticed about your code is you are mixing AWT and Swing components which can cause problems on some versions of Java. I suggest you change JFrame to Frame and see if it works on your system.


I tried importing a regular frame instead, the issue is:


EXIT_ON_CLOSE cannot be resolved or is not in a field. How should I fix this? I imported import java.awt.Frame; and changed all the JFrame to Frame.
 
Knute Snortum
Sheriff
Posts: 3556
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the issue is that the black and white just appears a little here and there in my window, but still in a pattern.


What is supposed to happen?
 
Tony Docherty
Bartender
Posts: 3209
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is an equivalent AWT method for this. It's a long time since I used AWT but I think you have to use a listener such as:
 
Knute Snortum
Sheriff
Posts: 3556
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I would tend away from AWT and towards Swing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!