Friday, February 24, 2012

ThreadLocal

Java has a useful class that is called ThreadLocal, this class can be used to store a value in a class and every thread that use the instance will have a value.

The best way to use it is to create a static variable.

public class Test{

  private static ThreadLocal<String> testName = 
          new ThreadLocal<String>();
}

If we one have one instance of the class Thread and this is access from different Threads, every Thread will have a testName value.

But How do we assing values? Easy, just do:


testName.set("FirstTest");

And now to get the value we use:


String name =  testName.get();

Tuesday, May 12, 2009

Run jar files on Windows Vista

If we install a program that stole the .jar association we can restore it, so when you double-click a jar file, it opens automatically.

To do this, you have to download and run JarFix program.

http://www.jonelo.de/java/jarfix/

After execution the association will be restored and now you can open jar files with double-click.

Friday, March 20, 2009

XNA using custom fonts

When we are creating a game one of the importat part is the text that we display, but we don’t want to use the boring fonts that our system has installed. The following steps helps us to add and use a new font in our game.

  1. Download new font
  2. Install font on the system
    1. In Windows XP: Copy the font file and paste it in /Windows/Fonts
  3. Create or Load a Project
  4. Right click in Content folder
    1. Add New Item
    2. Create a SpriteFont
      1. Change in <FontName> the name of the Font we want
      2. Change the other characteristics of the font (Optional)
  5. Use the Sprite Font in the Game

Note: If you send to someone the xna project the other members of the team also have to install the font in the system. This is not necesary when distributing the game.

Blogger Tags Cloud

If You want to add a Tags cloud to your Blog you can see this tutorial.

http://phy3blog.googlepages.com/Beta-Blogger-Label-Cloud.html

This tutorial is for Blogger and you have to add a “Labels widget” to the site

Friday, February 13, 2009

Compile a java package

When we compile a java file, we use the "javac" tool

javac File.java

The problem is that if we have packages and we have to compile them we might do it file by file. This solution has a problem because if files have references to other class in the package we have to compile them in an specific order. In order to do this task more easy we have to go to the root directory of the project and use javac tool:

javac package/sub-package/*.java

This will compile to us all the files in the package without problems