Java图像处理与动画实现详解
1. 全局变量与启动流程
在图像处理与动画实现中,有一个全局变量 counter
,初始值为 0,在每次 paintComponent()
调用结束时递增,使用取模 100 操作避免其值过大。这个变量在代码中多处使用,常作为视觉效果的输入参数。
启动程序时, main()
方法创建一个 JFrame
并添加 ImagesTests
面板:
public static void main(String args[])
{
// switch on translucency acceleration in Windows
System.setProperty("sun.java2d.translaccel", "true");
System.setProperty("sun.java2d.ddforcevram", "true");
// switch on hardware acceleration if using OpenGL with pbuffers
// System.setProperty("sun.java2d.opengl", "true");
ImagesTests ttPanel = new ImagesTests( );
// create a JFrame to hold the test JPanel
JFrame app = new JFrame("Ima