Posted on September 11, 2007 by Subin
A state machine is an entity, which handles the states of an entity by taking it thru various states, handles states’ entry - exit actions, controls the state transitions & transition actions.
Using state map compiler:
State map compiler helps us to design state machines easily. SMC has a well-defined format to write states, transitions & actions. [...]
Filed under: Advanced Java, Articles, Code Snippets, Design, Development Tools, Downloads | No Comments »
Posted on September 11, 2007 by Subin
Singleton design pattern is a creational pattern, which restricts the instantiation of objects. The designers need to keep three things in their mind before setting a class to follow Singleton pattern. One: make the constructor invisible. Two:provide a static method that can create a new instance only if no instance is available. Three: override the [...]
Filed under: Advanced Java, Articles, Code Snippets, Design, Tips | No Comments »
Posted on September 4, 2007 by Subin
package subin.rnd.nativity;
import java.io.IOException;
import java.io.InputStream;
public class NativityTest
{
public static void main(String[] args)
{
String cmd = “cmd /c dir”;
_runtime = Runtime.getRuntime();
executeCommand(cmd);
}
private static Runtime _runtime;
private static Process _process;
private static InputStream _inStream;
private static void executeCommand(String cmd)
{
System.out.println(“Executing > “ + cmd);
_inStream = null;
_process = null;
int ch;
try
[...]
Filed under: Code Snippets, Nativity | No Comments »
Posted on August 14, 2007 by Subin
I have attached a small code snippet which implements an SMS listener. For more details on PushRegistry click here. This will invoke notifyIncomingMessage() of the MessageListener. This code will not create a permanent entry in the registry, but will listen to the specified port as long as the application is alive.
package subin.rnd.mobile.game;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
public [...]
Filed under: Code Snippets, Mobility (J2ME & more), Multi Threading | No Comments »
Posted on August 6, 2007 by Subin
I have attached a sample code snippet for creating a Pie Chart using JFreeChart with custom colors. There is a PieReneder (a static inner class) which can be used to achieve the same. The PieRenderer takes an array of java.awt.Color in its constructor.
package subin.rnd.chart;
import java.awt.Color;
import java.io.File;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
public class PieChartWithCustomColours
{
public [...]
Filed under: Code Snippets, Graphics | Tagged: JFreeChart | No Comments »