• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sprites disappearing after scaling down window? Aaargh the frustration!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am so stumped here!

Ok, so I have a chess program that I am writing, and I can't for the life of me figure out what is wrong with my resize code. Any help is greatly appreciated!

EDIT: See 2 comments below for a short compilable example.

Problem: Every time I resize the window smaller, certain pieces disappear, however this problem only arises when I resize the window fast. If I gradually resize it smaller, the pieces don't disappear!?!? I have attached images of the problem.

Code Structure: The resize code is spread over 3 classes. The MainGui, the ChessBoard, and the ChessPiece class. The gamePanelComponentResize method resides in the MainGui class, and is a listener for the resize component event. This method then delegates the resize order to the ChessBoard object, which in turn delegates it to each of the remaining ChessPiece objects.

MainGui method:


ChessBoard Methods:




ChessPiece methods:
maximized.png
[Thumbnail for maximized.png]
Maximized, resize code runs again. Everything scales appropriately.
minimized.png
[Thumbnail for minimized.png]
Back to windowed mode, everything scaled down abrubtly. Whered the chess pieces go?
startup.png
[Thumbnail for startup.png]
How the game looks on startup, everything in its right place. Resize code has already run once.
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see no classes and no relations. If you could dumb down your problem to a SSCCE ... that would be great.
 
Tyler Eastman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I will trim down the fat and try to get a simple compilable example ready by the end of today.
 
Tyler Eastman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heres a simple compilable example of the problem. I apologize for the length of ChessBoard.java. Most of the code in that class is initialization code and can be ignored. The resizeBoard, setSize, and paintComponent methods are the only ones linked to the problem (that I'm aware of) in that class.

Thank you for taking the time to help!

MainGui.java


ChessBoard.java


ChessPiece.java


ChessSquare.java
board.png
[Thumbnail for board.png]
Image file for the chess board.
wpawn.png
[Thumbnail for wpawn.png]
Image file for a pawn. We will pretend each piece is a pawn for the example.
 
Tyler Eastman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea's guys? I'm thinking it might be thread related, however if I spawn a new thread each time the resize event is called, won't it be flooded with duplicate threads, all doing the same thing but with different size variables? Any thoughts?
Thanks guys!
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tyler Eastman wrote:Any idea's guys? I'm thinking it might be thread related, however if I spawn a new thread each time the resize event is called, won't it be flooded with duplicate threads, all doing the same thing but with different size variables? Any thoughts?
Thanks guys!



I've been looking at this, and I'm not sure, but I don't think that it's thread related, but much of the problem is that I can't see where the problem is since it is how Swing is calling your paint methods. The error occurs when the view is shrunk quickly, and when this happens, Swing doesn't paint all the components in the container (at least I'm not seeing the output from a println I have in a paintComponent displaying from all the components when this happens). As an aside, you know that you can and should simplify your code greatly by using arrays here.
 
Tyler Eastman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your fast response Pete! I will condense the piece initialization and resize code down using arrays once I'm at my home computer tomorrow, I can see how not using them adds unnecessary bulk to the example.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I'd simply use a GridLayout, there shouldn't be painting problems at all using the 'standard' layout managers. Animations could always be drawn 'on top' (e.g. on a glasspane).

 
Tyler Eastman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Peter, your example seems to have solved the problem completely! It will require me to restructure my animation code a little bit, but after pulling my hair out for 2 weeks on the resize code, it will be a welcome change of pace!

Thank you everyone for your help, it is very appreciated!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic