user interface - DoubleBuffering in Java -


I have a problem with implementing doublebuffers in my program. Before you become unconscious by text wall, you It should know that there is a lot in it, just you should know the real place, where I feel that I am having problems, in a method.

I have recently seen a tutorial about double buffering on gpwiki, and they tried and tried to implement the code code that i was trying to implement doublebuffer. I get the following error: "java.lang.IllegalStateException: The component must have a valid colleague."

I do not know if it makes any difference if you know or not, but the code with the following main method is it's just a frame that displays the ChronosDisplay class in it "I ..." Excluded irrelevant code with

  public class CDM Jeffreem {public CDM (string straw) {super ("CD: M -" + str); Try {... ChronosDisplay theGame = New ChronosDisplay (str); (Component) thegame) .setFocusable (true); (Thegame) add; } Hold (exception e) {System.out.println ("CDM error:" + E); }} Static zero main (string agr []) (cdm run = new CDM ("dpiimini");}}  

Here is the code where I think the problem is residing (I think the problem is in the paint () method). This class is displayed in the CDM class

  The public square repeats the ChronosDisplay canvas Runnabel {String mapName; Public ChronosDisplay (String Str) {mapName = str; new thread (this) .start (); setVisible (true); createBufferStrategy ( 2);} Public Zero Paint (Graphics Window) {Buffer Whistle B = Match Buffer Nitrogen (); Graphics G = Faucet; window.setColor (Color.white); Try {g = b.getDrawGraphics (); paintMap (g); paintUnits (G); paintBullets (g);} Finally {g.dispose ();} B. Show (); Toolkit.getDefaultToolkit () Sync (.).} Public Zero Paintmap (Graphics Window) {TowerMap m = New TowerMap (); Try {m = new tower mark (mapName); for (int x = 0; x & lt; m.getRows () * 50; x + = 50) {for (int y = 0; y & lt ; M.getCols () * 50; y + = 50) {int tiletype = m.get location (x / 50, y / 50); Image image; If (tile type == 0) {tile 0t = new tile 0 (x, y); T.draw (window); } ... // more similar if the statement for other integer} hold (exception e) ...} ... additional methods that have not been publicly publicized here {try {while {true} {Thread.currentThread () .sleep (20); Repaint (); If you are curious (I doubt it), there is a draw () method in the tile category:  
  Public Zero Draw (Graphics Window) {window.drawImage (IMG, getX (), getY (), 50,50, blank); }  

Any indication, suggestions or solutions greatly appreciated. Thanks for your time! Swing is a double buffer by default, so you do not have to apply it yourself. D

You should not use the canvas class in the swing application. This ADT and rotation components were not found.

All swing components should be made on EDT. Read the swing tutorial for example on how to do this.


Comments