Saturday, March 31, 2007

Display Busy Cursor in Java

Most guides and books will tell you that it is very easy to change the cursor in a Java application. For example, the following fragment of code sets the cursor to a busy cursor while it performs some processing, and then returns the cursor to the default cursor again afterwards.

import java.awt.Cursor;

// Setting cursor for any Component:

This is a good start but, somewhat surprisingly, this short code fragment contains a bug. The problem is that the main processing method might throw an exception. If the exception is not caught within the processing method, then the Java Virtual Machine unwinds the call stack repeatedly until it finds a try context that will catch the given exception. In other words, the flow of control may jump out of this (apparently) linear flow of control and we therefore cannot guarantee that the default cursor is restored. In short, if an exception is thrown, the busy cursor will remain there indefinitely!

Wednesday, March 21, 2007

Warcraft/ Frozen Throne - Dota Item Effect Calculation

Inside Dota, We know that most item effect is not direct stack, example with 1 basher hero will gain 15% of stun chance, but with 2 basher is not equal to 2 X 15% = 30% of stun chances.

The actual formula of multiple item should calculate based on :
Total % = Current % / 100 + (100 - Current %)/100 * Additional %/100

Tuesday, March 6, 2007