Monday, May 21, 2007

Java FX ... The X Factor !

Ah, so one more scripting language. It seems that we are going more and more lazy in writing code. Anyway, I am all set for JavaFX programing. So far looking cool. Downloading NetBeans solves most of the problem.

Setting up for Java FX: Here. First time saw anything that can be done easily in Java(because I guess its not Java :) )

And my Cruel World Program,

import javafx.ui.*;

var window = new Frame();
window.title = "Title Bar";
window.width = 400;
window.height = 200;
var label = new Label();
label.text = "Cruel World";
window.content = label;
window.visible = true;


By the way where is the class. Sir this is the world of Scripting :). I guess a easier way to write code with more smoothness and less tension of inheritance, abstract funda.

So, trying for a code, in which I will take my photo and zoom it. So Nice :D. Will comeback with code in next blog.

Sunday, May 20, 2007

Searching Impl.

This is one bad implementation of the last blog. Need to change a lot of part to run in generic way, I am too lazy :)


import java.util.*;
public class SearchFile
{
public static void main(String args[])
{
try
{
String osName = System.getProperty("os.name" );
System.out.println(osName);
String[] cmd = new String[5];
if( osName.equals( "Windows Vista" ) )
{
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "dir *.java /s";
cmd[3] = ">";
cmd[4] = "Hello.txt";
}
/* else if( osName.equals( "Unix" ) )
{
find name filename

...

} */
Runtime rt = Runtime.getRuntime();
System.out.println("Executing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]+ " " + cmd[3]+ " " + cmd[4]);
Process proc = rt.exec(cmd);
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTrace();
}
}
}

Look at the search speed after first run. Its simple awesome. But it will create problem if user dont have permission to run a process.

Friday, May 11, 2007

How to get ?

I was trying to automate some of my manual work, I came across one problem. Is java providing any option by which if I give the file name and directory name it will go ahead and search that file in the given directory or sub-directory and return me the complete path of the file ? Unfortunately not :(, there is no direct API that can do this work for me. But Kannan told me that one can make a code which can recursively do this work. And he already had written some code for this. I was trying to tackle this problem with a different approach. The approach is something like:

On windows, dos gives me an option to search a file in a dir or sub-dir by command:
dir filename /s
Linux and Solaris gives me option of search the same by command: find /directory_name filename
So, why not using the runtime option of java system class and write a code like:

if ( OS == Windows) {get it by dir filename /s}
elseif (OS == Linux or Solaris or Unix){get it by find /directory_name filename}
else {God Knows only :)}
Right now I am not ready with code(because this dos is not giving anything directly, so need to remove useless things) but will come back soon with the results and the optimal code. Any suggestions are most welcome.