スキップしてメイン コンテンツに移動

投稿

ラベル(Animation)が付いた投稿を表示しています

Render FPS Text on Java Swing Component

In the previous post , I showed helper class for 2D animation on Java Swing component. If we can measure the frame rate of animation, it is very great, isn't it? In this post, I will show you that kind of class - rendering FPS text on swing component. Showing code is fast and snappy :p Here is the code - count frame per 1 sec. package com.dukesoftware.utils.awt.graphics; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.text.DecimalFormat; public class FPSText { protected static final String FPS = "FPS: "; private static final int FONT_SIZE = 24; private static final int FONT_STYLE = Font.BOLD; private static final String FONT_NAME = "SansSerif"; protected final static Color COLOR = new Color(0.55f,0.55f,0.55f); protected double frameCount; protected final DecimalFormat format = new DecimalFormat("####.00"); protected String fpsText; protected fin

Java 2D Animation on Swing

In this post, I will show you some tips (or tools) for 2D animation on Java Swing component. There are 2 ways to rendering animation on Swing compinent - Thread vs Timer. I think Swing rendering is based on single thread model, so we should use Timer. But I have used separate thread for executing animation and it works fine, so should be fine for not critical application. Animator class Ok then, I can show you a simple animator canvas class I created. The class takes Model2D for actual animate model and render it. One thing you should remember - AnimateCanvas calculate model of animation (coodinates or position or whatever) on animation rendering process, so if the calculation takes takes log time, the animation cannot meet the frame per second passed to constructor. package com.dukesoftware.utils.swing.others; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.aw