Index CH25 (12) 03 (210) sztuka rozbierania Orson Scot Card Cien Endera Buchanan Edna Nie igra sie z Miami 08 (17) Harrer Heinrich 7 lat w Tybecie Inwazja Zbigniew Nienacki Pan Samochodzik i Wyspa Zloczyncow www nie com pl 1 |
[ Pobierz całość w formacie PDF ] .addImage(frames[i],i); } public void paint(Graphics g) { if(allLoaded()) g.drawImage(frames[currentFrame],10,10,this); else{ String stars = "*"; for(int i=0;i<currentFrame;++i)stars += "*"; g.drawString(stars,60,60); } } boolean allLoaded() { for(int i=0;i<numFrames;++i) { if(tracker.statusID(i,true) != MediaTracker.COMPLETE)return false; } return true; } public void run() { do { long time = System.currentTimeMillis(); if(time - lastDisplay > frameDelay){ if(allLoaded()) { if(fullDisplay) repaint(10,90,160,78); else{ fullDisplay= true; repaint(); } }else repaint(); try { Thread.sleep(frameDelay); }catch(InterruptedExceptionex){ } ++currentFrame; currentFrame %= numFrames; lastDisplay = time; } } while (true); } public boolean handleEvent(Event event) { if(event.id==Event.WINDOW_DESTROY){ System.exit(0); return true; }else if(event.id==Event.ACTION_EVENT){ if(event.target instanceof MenuItem){ String arg = (String) event.arg; if("Exit".equals(arg)){ System.exit(0); return true; } } } return false; } }When you run GraphicUpdateApp,it displays an animated string of asterisks while the image filesare being loaded.After that, it will immediately display theimage animation.This reduces the unsightly flickering causedwhen an image is displayed while it is being loaded.Notice how GraphicUpdateAppimplements the limited-area repainting.You can run your mouseover the image display to determine the boundaries of the repaintarea.You should also notice that GraphicUpdateAppdisplays images at a slower rate.The frame- delay rate was increasedfrom 100 microseconds to 200 microseconds, decreasing the framedisplay rate by a factor of 2.The changes made to GraphicAnimationAppby GraphicUpdateApp consistof the declaration of the fullDisplayand tracker variables andmodifications to the setup(),paint(), and run()methods.In addition, the allLoaded()method was created:The fullDisplayvariable is used to ensure that a full display of the stickmanis accomplished before attempting a limited display using therepaint() method.The trackervariable is used to refer to a MediaTrackerobject.The setup()method is updated to create the MediaTrackerobject and to add the images being loaded with this object.The paint()method is updated to draw the images after they've been loadedand to draw asterisk strings before the images are loaded.The allLoaded()method uses the statusID()method of the MediaTrackerclass to determine whether all images have been completely loaded.The run()method has been modified to use the allLoaded()method and the fullDisplayvariable to determine whether it should repaint the entire screenor only a limited portion of it.SummaryThis chapter shows how to include animation sequences in yourwindow programs.It identifies the basic elements of implementingan animation and describes approaches to improving the qualityof an animation's display.It shows you how to selectively repaintparts of a window and how to use the MediaTrackerclass to support the loading of the images used in an animation.Chapter 26, "Client Programs,"begins Part V, "Network Programming."Contactreference@developer.com with questions or comments.Copyright 1998EarthWeb Inc., All rights reserved.PLEASE READ THE.Copyright 1998 Macmillan Computer Publishing.All rights reserved [ Pobierz całość w formacie PDF ] |
||||
Wszelkie Prawa Zastrzeżone! Kawa była słaba i bez smaku. Nie miała treści, a jedynie formę. Design by SZABLONY.maniak.pl. | |||||