My single test SWT vs Swing

December 21st, 2008

code goes like this

[swt]

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;

public class HelloWorld {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
int hunter = 0;
int house = 0;
for (int counter = 0; counter <= 400; counter++) {
Button b = new Button(shell, SWT.CENTER);
b.setText(counter+”");
b.setBounds(house, hunter, 40, 40);
hunter += 40;
if (hunter >= 600) {
hunter = 0;
house += 40;
}
}

// label.setText(”Hello, World”);
// label.setBounds(shell.getClientArea());
shell.open();
shell.setText(”what is this”);
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}

[swing]

import javax.swing.JButton;
import javax.swing.JFrame;

public class Swing {

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLayout(null);
int hunter = 0;
int house = 0;
for (int counter = 0; counter <= 400; counter++) {
JButton b = new JButton();
b.setText(counter + “”);
b.setBounds(house, hunter, 50, 50);
frame.add(b);
hunter += 50;
if (hunter >= 600) {
hunter = 0;
house += 50;
}
}
}

}

Viewing memory taken in windows vista with jdk1.6 update 10

SWT takes about 10,160  KB
Swing takes about 16,429 KB

So i am planning to go with SWT and leave spring finally now

Thanks

With PL/JAVA

December 20th, 2008

PostgreSQL is my boss’s choice as an alternative for high cost oracle. I have been making tests to find if it really suits our requirement .

Here is why i found out PG is better than MYSQL

1) The oracle like sequences
2) better java suport
3) writing stored procedures in java
4) better support for .net platform

Can oracle be replaced with PGSQL is still a question but what i conclude is with PL/java around PGSQL is always better option for Online transaction processing JAVA applications

Setting PL/JAVA under windows is bit tricky we need to have path set to the JAVA_HOME/jre/bin/client where jvm.dll reside and also to the path where there is pljava.dll

for giving the path of the jar files in postgre.conf we used \\ instead of using \ or / and java under pg is working great

Thanks

done with dainikee.com and myrepublica.com

December 8th, 2008

finally done with
dainikee.com and myrepublica.com

fun working..

Away3d

November 3rd, 2008

Lights, Camera, Scene view and 3d Models
using away3d with flash is fun and having my window less desktop application in AIR is more fun.

view the demo

flash demo with AWAY 3d

Bug in Astro(Flash 10) or My mistake

August 29th, 2008

Trying to rotate a cube in flash 10 with its new 3D features
I placed a movie clip at z index 1 having alpha 0.5
I placed a movieclip at z index 50 having alpha 1 and again i placed movie clip at z index 100 with alpha 1

I can view the last movie clip as because the alpha is 0.5 for the the two upper movie clip but when i rotate the movie clip and when the last movie clip comes to front then still i can view the two movie clip which is not quite natural in case of 3d objects the code goes as follows

=============================================

package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;

public class Regauqablo extends MovieClip
{

private  var container:MovieClip=new MovieClip();
private var glassBox:MovieClip=new MovieClip();
private var pane1:GlassPane=new GlassPane(0xffffff);
private var pane2:GlassPane=new GlassPane(0xffffff);
private var pane3:GlassPane=new GlassPane(0xffffff);
private var pane4:GlassPane=new GlassPane(0xffffff);
private var pane5:GlassPane=new GlassPane(0xffffff);
private var pane6:GlassPane=new GlassPane(0xffffff);

private var back:GlassPane=new GlassPane(0xff0000);

[Embed(source=”LILY.jpg”)]
private var Lily:Class;

//  private var back:Bitmap= new Lily();

public function Regauqablo()
{
pane1.alpha=1;
pane2.alpha=0.5;
pane3.alpha=0.5;
pane4.alpha=0.5;
pane5.alpha=0.5;
pane6.alpha=0.5;
back.alpha=0.5;

glassBox.addChild(pane1);

glassBox.addChild(pane2);
pane2.rotationX=270;

glassBox.addChild(pane3);
pane3.rotationY=90;

pane4.x+=pane4.width;
glassBox.addChild(pane4);
pane4.rotationY=90;

pane5.y+=pane5.height;
glassBox.addChild(pane5);
pane5.rotationX=270;

glassBox.addChild(pane6);
glassBox.addChild(back);

pane1.z=200;
pane2.z=200;
pane3.z=200;
pane4.z=200;
pane5.z=200;
back.z=100;

glassBox.x=100;
glassBox.y=100;

this.addChild(glassBox);
this.addEventListener(Event.ENTER_FRAME,doFrame);

}

function doFrame(e:Event):void
{
this.glassBox.rotationY+=.5;
}

}
}

import flash.display.*;
class GlassPane extends MovieClip
{

public function GlassPane(color:uint)
{
this.graphics.moveTo(0,0);
this.graphics.beginFill(color,1);
this.graphics.moveTo(200,0);
this.graphics.lineTo(200,200);
this.graphics.lineTo(0,200);
this.graphics.lineTo(0,0);
this.graphics.endFill();
}

}

=====================================

please check the file below for the output (FLASH 10 player needed)

regauqablo.swf

Astsro And Me

August 26th, 2008

Last week I downloaded Flash 10 SDK(Astro)
The 3d Thing (post card in space) is cool i am able to make a cube and rotate the cube in x ,y,z roatation . Till now flash does not have camera, Models and textures but shaders are great

I got Adobe pixel blender tool and tried with flash i was not able to run it smoothly as my graphics card (ATI) was not among the supported list of GPU for pixel blender

Flash 3 has

SoundMixer.getSprectrum for getting the spectrum of the sound .
few years back that was a hard thing for me to do in Java Sound api but now it is not even 3 single line of code here is my code in flash 10 AStro for rotatating a cube with the music

package
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import flash.net.*;
import flash.filters.*;

[SWF( backgroundColor=”#000000″, frameRate=”31″)]
public class Test extends MovieClip
{

[Embed(source=”yourpicture file.jpg”)]
private var Mypic:Class ;
private var mySound:Sound;

private var cont:MovieClip=new MovieClip();

private function soundLoaded(e:Event):void
{

mySound.play();

}
var n:Bitmap=new Mypic();
public function Test()
{

mySound=new Sound();
var soundFile:URLRequest =new URLRequest(”your soung file.mp3″);
mySound.load(soundFile);
mySound.addEventListener(flash.events.Event.COMPLETE,soundLoaded);

cont.addChild(n);
var n2:Bitmap=new Mypic();
cont.addChild(n2);
n2.rotationX=270;
addChild(cont);
var n3:Bitmap=new Mypic();
cont.addChild(n3);
n3.rotationY=90;
var n4:Bitmap=new Mypic();
n4.x+=n4.width;
cont.addChild(n4);
n4.rotationY=90;
var n5:Bitmap=new Mypic();
n5.y+=n5.height;
cont.addChild(n5);
n5.rotationX=270;
var n6:Bitmap=new Mypic();
cont.addChild(n6);
n.z=197;
n2.z=197;
n3.z=197;
n4.z=197;
n5.z=197;
cont.x=100;
cont.y=100;

var tTimer:Timer = new Timer(5, 0);
tTimer.addEventListener(TimerEvent.TIMER, doit);
tTimer.start( );

cont.alpha=0.5;

}

function doit(g:Event):void
{

var spectrum:ByteArray = new ByteArray( );
SoundMixer.computeSpectrum(spectrum);
var nos:Number=0;
cont.rotationX+=1;

cont.rotationY-=1;
for (var i:int = 0; i < 256; i++) {
nos = (spectrum.readFloat() );
cont.rotationZ-=(nos*10);

}

}

}

}

and here is the rotation of cube with out the music The rotating cube in flash 10


Technologies we Used for the election commission of Nepal

April 12th, 2008

Ok here is the list of technologies that we used for the election commission

  • Database DB2 [gifted to Election commission of Nepal from IBM]
  • Desktop program in Visual Basic 6 with extensive use of VSFlex grid
  • Desktop Reporting and Book printing in Crystal Reports 6
  • PHP web application
  • extensive use of xml and ajax(javascript) for playing with the offline database
  • using actionscript 2 and flash 8 for generating the charts
  • Using java, Apache net tools and J2ssh for perodic updates of the files in the ftp server
  • Using Ext2 js for interactive web page[a little]  

Storing the directory structure in a zip file(java)

April 12th, 2008

simple
just add the zipentry files containng the file path
like
ZipEntry e=new ZipEntry(”abc/a.txt”);
ZipEntry e2=new ZipEntry(”efg/a.txt”);

will keep 2 folders abc and efg with two files

SSH login+SFTP using java and execute command

April 12th, 2008

Dear All
I needed to automate the login to a ssh client and execute some commands after hours of googling and trying couples of API and free tools i conclude that the best tool for me is j2ssh is
http://sourceforge.net/projects/sshtools

Here is snapshot of how you can login and fire some commands

ConfigurationLoader.initialize(false);

SshClient ssh = new SshClient();

ssh.setSocketTimeout(30000);

SshConnectionProperties properties = new SshConnectionProperties();

properties.setHost(this.server);

properties.setPrefPublicKey(”ssh-rsa”);

// Connect to the host

ssh.connect(properties);

// Create a password authentication instance

PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();

// Get the users name

pwd.setUsername(this.user); // Get the password

pwd.setPassword(this.password);

// Try the authentication

int result = ssh.authenticate(pwd);

// Evaluate the result

this.field.setText(”firing command”);

SessionChannelClient session = ssh.openSessionChannel();

session.requestPseudoTerminal(”vt100″, 80, 24, 0, 0, “”);

if (session.startShell()) {

ByteArrayInputStream ins1 = new ByteArrayInputStream(”cd reports;cd CAResults;unzip -o ToUpload.zip\r”.getBytes());

//ByteArrayInputStream ins2=new ByteArrayInputStream(”cd reports\r”.getBytes());

// ByteArrayInputStream ins3=new ByteArrayInputStream(”cd reports\r”.getBytes());

IOStreamConnector input = new IOStreamConnector();

IOStreamConnector output = new IOStreamConnector();

IOStreamConnector error = new IOStreamConnector();

output.setCloseOutput(false);

input.setCloseInput(false);

error.setCloseOutput(false);

input.connect(ins1, session.getOutputStream());

output.connect(session.getInputStream(), System.out);

error.connect(session.getStderrInputStream(), System.out);

// session.getState().waitForState(ChannelState.CHANNEL_CLOSED);

Thread.sleep(30000);

this.field.setText(”Over and out from USA”);

session.close();

Here is how you can do SFTP

ConfigurationLoader.initialize(false);

this.clientS = new SshClient();

clientS.connect(this.server);

PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();

pwd.setUsername(this.user);

pwd.setPassword(this.password);

int result = clientS.authenticate(pwd);

this.client = clientS.openSftpClient();

this.client.cd(this.workingdir);

this.field.setText(this.client.pwd());

this.client.put(local.toString());

Happy new year

April 10th, 2008

Happy new year Card to all my frens and my moti