Java 连连看游戏分数动画实现 - ScoreAnimate 类详解
The ScoreAnimate class is a JPanel that displays the score of the game. It implements the Runnable interface, allowing it to run on a separate thread and animate the score as it increases.
The class contains a 'thread' variable and methods to start and stop the thread. It also has variables for the 'lastScore' and 'currentScore', allowing it to track changes in the score and update the display accordingly.
The 'paint' method is responsible for drawing the score on the panel using a Graphics2D object. It sets the font, color, and rendering hints before drawing the score using the DecimalFormat class to format the number with leading zeros.
The 'run' method is the main method that runs on the thread. It increments the 'lastScore' by one and calls 'repaint' to update the display. It then sleeps for a short period of time before repeating the process until the 'lastScore' matches the 'currentScore'.
The 'setScore' method is used to set the 'last' and 'current' score, and start the thread. The 'stop' method is used to stop the thread if it is running.
原文地址: https://www.cveoy.top/t/topic/n5k8 著作权归作者所有。请勿转载和采集!