Friday, June 27, 2008

ManU - Eyeing a dual title

With Arsenal well out of their way, Manchester United are nearly assured of their league title. Their only threat is the renewed Chelsea with the super energized Nicolas Anelka. If ManU defeats Chelsea at Stanford Bridge, they will be completely confirmed of their title.


If anything is not to change, their form this season could event get them closer to their dream of winning the champions league along with the EPL title.

GO FOR IT DEVILS!!!!

Thursday, June 19, 2008

Java Robot Class for accessing your system from a mobile phone

I was doing a simple program for my friend, when I came up across the Robot class in java. His project is accessing a system from a mobile phone. So he needs to get the screen shot, move mouse and right and double click mouse buttons. Just the Robot class is enough for this purpose.

There are methods like mouseMove, mousePress and even for getting screenshots of the system.
Once I complete the coding, i think of releasing the software as a complete package.

I decide to use Tomcat for acting as server and a j2me program for doing the job in the mobile phone.

Below is the code:-

Tomcat web pages for Screenshot, Mouse move and mouse clicks:-

Screenshot:-(mapped as screenshot.html inside tomcat)
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.awt.geom.AffineTransform;

public class screenshot extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
try
{

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rect = new Rectangle(0, 0,screenSize.width,screenSize.height);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rect);
File file;
int w = 220;
int h = 280;
BufferedImage image1 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image1.createGraphics();
double xScale = (double)w / image.getWidth();
double yScale = (double)h / image.getHeight();
AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
g2d.drawRenderedImage(image, at);
g2d.dispose();
file = new File("C:/Tomcat-4.1.31/webapps/ROOT/screen.jpg");//root folder of the server
ImageIO.write(image1, "jpg", file);
pw.println("ok");
}
catch (Exception e)
{
pw.println("error");
}
}
}

//Here i have tried to reduce the screenshot size to the standard mobile phone screensize

MouseMove:-

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;



public class MouseMove extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
try
{

int x = Integer.parseInt(req.getParameter("x"));
int y = Integer.parseInt(req.getParameter("y"));
Robot robot = new Robot();
robot.mouseMove(x,y);

}
catch (Exception e)
{
pw.println("error"+e.toString());
}
}
}


MouseClick:-
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;



public class MouseClick extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
try
{

int x = Integer.parseInt(req.getParameter("x"));
int y = Integer.parseInt(req.getParameter("y"));
String mode = req.getParameter("type");
Robot robot = new Robot();
if(mode.equals("right")){
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON3_MASK);
robot.mouseRelease(InputEvent.BUTTON3_MASK);
pw.println("ok");
}
else if(mode.equals("left")){
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
pw.println("ok");
}
else if(mode.equals("left-double")){
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
pw.println("ok");
}
else
{
pw.println("error:wrong mode");
}
}
catch (Exception e)
{
pw.println("error"+e.toString());
}
}
}


And the j2me program:-
SM1.java:-

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import java.lang.*;
import java.util.*;


public class SM1 extends MIDlet implements CommandListener {

public Command exitCommand;
public Command ScreenCommand;
public Command MouseCommand;
public Command MPressCommand;
public Command MRClickCommand;
public Command MLClickCommand;
public Command MLDClickCommand;
public ntclient nt = null;
public MouseClient mc = null;
public Command BackCommand;
private Display display;
public TextField tx;
public TextField ty;
public Form displayForm;
public Form MouseForm;

public SM1() {

display = Display.getDisplay(this);
exitCommand =
new Command("Exit", Command.SCREEN, 1);
ScreenCommand =
new Command("ScreenShot", Command.SCREEN, 1);
MouseCommand =
new Command("Mouse", Command.SCREEN, 1);
MPressCommand =
new Command("Move", Command.SCREEN, 1);
BackCommand =
new Command("Back", Command.SCREEN, 2);
MRClickCommand =
new Command("RightClick", Command.SCREEN, 2);
MLClickCommand =
new Command("LeftClick", Command.SCREEN, 2);
MLDClickCommand =
new Command("LeftDoubleClick", Command.SCREEN, 2);
}

public void startApp() {
displayForm = new Form("Exchange Rate");
displayForm.addCommand(exitCommand);
displayForm.setCommandListener(this);
displayForm.addCommand(ScreenCommand);
displayForm.setCommandListener(this);
displayForm.addCommand(MouseCommand);
displayForm.setCommandListener(this);

display.setCurrent(displayForm);


}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }

public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
else if(c == ScreenCommand){
nt = new ntclient(this);


}
else if(c == MouseCommand){
MouseForm = new Form("Mouse Movement");
tx = new TextField("Enter x","",4,TextField.NUMERIC);
ty = new TextField("Enter y","",4,TextField.NUMERIC);
MouseForm.append(tx);
MouseForm.append(ty);
MouseForm.addCommand(BackCommand);
MouseForm.setCommandListener(this);
MouseForm.addCommand(MPressCommand);
MouseForm.setCommandListener(this);
MouseForm.addCommand(MRClickCommand);
MouseForm.setCommandListener(this);
MouseForm.addCommand(MLClickCommand);
MouseForm.setCommandListener(this);
MouseForm.addCommand(MLDClickCommand);
MouseForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(MouseForm);
}
else if(c==BackCommand){
Display.getDisplay(this).setCurrent(displayForm);
}
else if(c==MPressCommand){
mc = new MouseClient(this,"http://127.0.0.1:8080/MouseMove.html?x="+tx.getString()+"&y="+ty.getString());
}
else if(c==MRClickCommand){
mc = new MouseClient(this,"http://127.0.0.1:8080/MouseClick.html?x="+tx.getString()+"&y="+ty.getString()+"&type=right");
}
else if(c==MLClickCommand){
mc = new MouseClient(this,"http://127.0.0.1:8080/MouseClick.html?x="+tx.getString()+"&y="+ty.getString()+"&type=left");
}
else if(c==MLDClickCommand){
mc = new MouseClient(this,"http://127.0.0.1:8080/MouseClick.html?x="+tx.getString()+"&y="+ty.getString()+"&type=left-double");
}
}

String getViaHttpConnection(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
StringBuffer str = new StringBuffer();

try {
c = (HttpConnection)Connector.open(url);
String type = c.getType();
is = c.openInputStream();
int len = (int)c.getLength();
int ch;
while ((ch = is.read()) != -1) {
str.append((char)ch);
}

} finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
return str.toString();
}
}


class ntclient implements Runnable{
private SM1 parent = null;
public Thread processorThread = null;
public ntclient(SM1 parent)
{
this.parent = parent;
processorThread = new Thread(this);
processorThread.start();
}
public void run(){
try
{

String result = parent.getViaHttpConnection("http://127.0.0.1:8080/screenshot.html");
if(result.indexOf("ok")>=0)
{
parent.displayForm.append("screenshot " + result);
System.out.println(result);

MyCanvas canvas = new MyCanvas(parent);
Display.getDisplay(parent).setCurrent(canvas);

}
else
{
parent.displayForm.append("error taking screenshot");
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}

class MouseClient implements Runnable
{
private SM1 parent= null;
public Thread pThread = null;
public String url = null;
public MouseClient(SM1 parent,String url)
{
this.url = url;
this.parent = parent;
pThread = new Thread(this);
pThread.start();
}
public void run()
{
try{
String result = parent.getViaHttpConnection(url);
parent.displayForm.append("MouseEvent "+result);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}

class MyCanvas extends Canvas implements CommandListener
{
private Command exit;
private SM1 parent;
private Image image=null;
private Display display;
public Image getImageFromUrl(String url)
{
InputStream is = null;
HttpConnection hc = null;
Image img = null;
try {
hc = (HttpConnection)Connector.open(url);
if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
is = hc.openInputStream();
int len = (int)hc.getLength();
byte[] data = new byte[len];
int actual = is.read(data);
img = Image.createImage(data, 0, len);
}
} catch (Exception e) {
System.out.println("IO Exception+"+e);
} finally {
if (is != null) {
try {
is.close();
}
catch (Exception e) { }
}
if (hc != null)
{
try {
hc.close();
}
catch (Exception e) { }
}
return img;
}
}
public MyCanvas(SM1 parent)
{
this.parent = parent;
exit=new Command("Exit", Command.EXIT,1);
addCommand(exit);
setCommandListener(this);

try
{
image = getImageFromUrl("http://127.0.0.1:8080/screen.jpg");
}
catch(Exception err)
{
Alert alert=new Alert("Failure","Can't open the image file",null,null);
err.printStackTrace();
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(parent).setCurrent(alert);
}
}
protected void paint(Graphics g)
{
if(image!=null)
{
g.drawImage(image,0,0,Graphics.TOP|Graphics.LEFT);
}
}
public void commandAction(Command command,Displayable display)
{
if(command==exit)
{
Display.getDisplay(parent).setCurrent(parent.displayForm);
}
}
}

/*by Arun Srinivasan*/


Hope to finish this one day.

Sunday, June 15, 2008

IPL battle begins

The Indian Premier League(IPL) is starting from the 18th. I support for the chennai team. I do have one of my best friends - R. Ashwin playing there. I'm really excited. The first match is to be between Bangalore Royal challengers and the Kolkatta Knight Riders. On paper, the Kolkatta team has the stronger batting line up with Ganguly, Ponting, Gayle, Hafeez, Butt. But the match is not won or lost in paper. Considering the present scenario though, the Bangalore team is suffering from more injuries. Their star player kumble is likely to miss the first match. Their batting aso lacks explosiveness with only virat kohli, cameroon white to provide them with the fire power. Kallis, Dravid are expected to provide for stability in the middle of the innings. Their bowling heavily banks on steyn. So I now go for Kolkatta Knight riders to walk thru the match, if not, Storm thru it.



vs

The Costliest Phones in the World

The mobile phones have become an important part of our daily life. The following are some of the costliest ones ever.

Diamond crypto smartphone


This phone is designed by Peter Aloisson and costs a whopping $1.3 million. It has 50 diamonds of which 10 are the rare blue diamonds. It also has powerful encryption technology to provide higher security. It runs on Windows CE Operating System and can store 4000 phone book details.

Diamond Embedded Motorola KRZR
This phone comes after the diamond crypto smartphone. Its Price depends on the number of diamonds you want on it which is customizable. It is available in 3 designs - White, Leopard and Roma.

Piece Unique

This is one of the three phones created by Swiss company, Goldvish. One of them was sold for a record price of 680,000 pounds to a Russian Millionaire at the Millionaire's fair at Cannes. The other is owned by a Hong Kong business man. The third is up for grabbing though!!!


Motorola V3i Stainless Steel/Gold with 855 Zirconia Diamonds

This phone is from the same person Peter Aloisson who designed the Diamond Crypto Smartphone and the diamond crusted Motorola KRZR. This one has been designed for the rappers. This comes with AAA grade diamonds and costs $10,000 for the Gold version and $2000 for the Stainless Steel version.

Vertu's Signature Cobra

This phone costs $310,000 and is made from one pear-cut diamond, one round white diamond, 2 emerald eyes and 439 rubies with all the rich stones by French jeweler Boucheron. A low end version is available for $115,000.

Vertu's Diamond

This phone costs $88,000 dollars and is made of 18 carat yellow or white gold set with pave diamonds as well as a platinum handset with a .25 carat solitaire diamond. Each handset takes seven days to complete because the craftsmen have to arrange more than 700 diamonds by hand. A pink variant has also been released.

Vertu's Ascent Ti

This phone is one that was launched in India and costs Rs3,26,000 or $8150. It is cheaper comparing the other models from Vertu. It has a backup utility which stores your data to a remote Ex- military server, thereby even if you loose your mobile you can get a new one with all your data.


My phone in comparison to all the above cost me just $120.

Saturday, June 14, 2008

Problem facing India in IT Field

India could very well be left out of the list of countries that most of the US companies outsources to. The scenario is something that has to be looked in with much of facts. The main reason that US was interested in outsourcing to East Asian countries was with the low cost of labor here. But it might soon end if government doesn't decide to act soon. Indian Rupee has been gaining in value against the Dollar and all that made the US companies to feel comfortable with low cost high labor seems to be eroding. Recently, TCS has thrown out 500 of its employees and with other companies expected to follow in line, the situation looks grim not just for the experienced employees but also for the newbies placed in those companies. Even the government has been trying to keep the Rupee - Dollar in check by doing various things, but all in vain.

I fear about the students who have been placed in those companies. They might be forced to work for extra hours with practically no or little improvement in pay. It's hard to say but I'm among those newbies placed in one of the IT Companies.

I hope that something well happens soon.

Friday, June 13, 2008

world's biggest dogs

The World's Biggest Dogs in action












Monday, June 9, 2008

Flash AS3 based Web Browser

Flash has been slowly and steadily incorporating many new features day by day. Considering the wide range of support available for flash, One could expect a lot of internet and system applications in it. The initial Support offered by flash for making html request was limited to methods like LoadVars() and Load().

With Flash AS3, they have added an important class for making and handling HttpRequest. The class is URLLoader(). I tried to get the html contents from a html Page using the following bit of code. and to say the least it succeeded, quite nicely. At the next stage, I'll be trying to create a renderer in flash. This I believe will be the toughest part. This is the initial bit of code.


import flash.net.*;
import flash.display.Sprite;
import flash.events.*;


var loader:URLLoader;

var loadeddata:String;

stop();


//handling a button click event for clicking the go button

function handleGoClick( e:Event ):void {
Text1.text = "";
Status1.text = "";
Status2.text = "";
loader = new URLLoader(new URLRequest(Address.text));
loader.addEventListener( Event.COMPLETE, handleComplete );
loader.addEventListener(ProgressEvent.PROGRESS, handleProgress );
loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, handleStatus );
loader.addEventListener( IOErrorEvent.IO_ERROR, handleIOError );
};


function handleIOError(e:IOErrorEvent):void {

Status2.text = e.text;
};

function handleProgress( e:Event ):void {
var percent:Number = Math.round( (e.currentTarget.bytesLoaded /
e.currentTarget.bytesTotal ) * 100 );

Status2.text = "loaded " +percent+ "% of "+Math.round(e.currentTarget.bytesTotal/1000)+ " KB";
};


function handleComplete( e:Event ):void {

Text1.text = loader.data;
};


function handleStatus(e:HTTPStatusEvent) :void {

if(e.status != 404)
Status1.text = "File Found:" +e.status+ " ";
else
Status1.text = "File Not Found:" +e.status+ " ";
};


ButtonGo.addEventListener(MouseEvent.CLICK, handleGoClick );

I have uploaded the files here :-

Flash Browser

Hope one day I can have a complete flash based web browser

You might need the latest version of adobe flash player for running the swf!!!!!

Saturday, June 7, 2008

Cable War between Hathway and SCV

Now Its the best time for people in Chennai. Both Hathway and SCV are offering free Set Top Boxes. So the customer has to pratically pay only the subscription charges.
The SCV was the first to announce to give away STB's at Rs. 499 (actually it was 500 + 200 + subs fees). Then Hathway announced free STB's just after rumours came that it has been bought by the government run Arasu Cable Vision. SCV in its turn, now has come up with free STB's. So chennaiites can hereafter be happy.

Thursday, June 5, 2008

An Indian's Aussie Campaign

My friend Deebak used to be playing a cricket selector game named "captain of captains". To mention, he is a very very good left handed batsman. At first, I thought it was useless and he was wasting his time.

But today he has shown me, that I was wrong. Just not before a month, he topped the game's initial season as the winner and won an all expenses paid trip to Melbourne to watch the Boxing day test match between India and Australia. Now even I have started playing it with much interest and even take his advice on everyday teams.

He is a good pal of mine. Hope even I could do something like him and probably win in the next season!!!!



My encouraging words for him:-
"All the best for next season pal!!!!!!!!!!!"

Tuesday, June 3, 2008

My First Post

For long has the thought of having my own blog crossed my mind..............

So today I'm starting on it..........


"thy who shall not seek the grail shall have its pride"