Thursday, August 06, 2009

Wednesday, June 17, 2009

Me and Sheldon Cooper

Sheldon Cooper... For those of you who don't know who this is .. he is one of the main characters in the Sitcom The Big Bang Theory

He is a socially awkward genius (whose IQ is 187 or something). Well i am not that intelligent, but other than intelligence part, i see a lot of similarity between me and him. The things that I most resemble Sheldon was his compulsive need to organise things, inability to understand others emotions.

One incident that i really loved was the interaction between Sheldon and Penny. It goes like this:


Sheldon: He asks something to Penny about a situation hes stuck in..and asks her help to solve it

Penny:Honey, I know you are thinking you are explaining yourself, but you are not


Well the above sentences is exactly how most of my conversations go with my friends. I keep telling them blah blah blah and finally after i have finished they just ask... "WHAT WAS THAT ALL ABOUT?". Well there are a couple who really understand my blabbering, other than them everyone else either just ignore me or just nod their head to shut me up.

Well thats enough. If I write more then again it will be same story :)

Monday, June 15, 2009

Evolution of Windows OS

A mail forwarded by my friend. Shows the evolution of UI from Windows 1.0 to Windows 7


Windows 1.0



Windows 2.0



Windows 3.0



Windows 3.11



Windows 3.11NT




Windows 95



Windows 98



Windows 2000



Windows Millennium Edition



Windows XP



Windows Vista



Windows 7

Friday, June 05, 2009

A Notification Window in Java

Tray Icon is a nice feature in Java 1.6. Very easy to write an application that sits in the tray and works. The thing that I really needed and didn't find was to show a message from the tray icon in a custom window. Now everywhere I searched I just came across the displayMessage(...) api of the tray icon. This is really useful if you are showing a message like a windows bubble message. Instead if you want to show some custom formatted message in your own window, you are lost, no solution in Tray Icon.

What do we do? Simple write a simple Window in Java Swing that scrolls up from the bottom right corner.

Presented below is a sample program, that shows a scrolling up window. The code is pretty much self explanatory. So without blabbering, here's the code:


public class PopupWindowTest {

private static final long serialVersionUID = 1L;
private static final Integer STARTING_POS_X = 300;
private static final Integer STARTING_POS_Y = 300;

public void showMessage(String text) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Toolkit t = Toolkit.getDefaultToolkit();
JTextArea area = new JTextArea(7, 30);
JPanel panel = new JPanel();
JFrame frame = new JFrame();
final JWindow window = new JWindow();

final JButton ok = new JButton("Click Me");
ok.setSize(40, 20);

final JButton close = new JButton("Close");
ok.setSize(20, 20);

ActionListener listener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == ok){
JOptionPane.showMessageDialog(null, "Just a sample message.");
} else if (e.getSource() == close){
window.dispose();
}
}};

ok.addActionListener(listener);
close.addActionListener(listener);

area.setEditable(false);
area.setOpaque(true);
area.setAutoscrolls(true);
area.setText(text);
area.setBackground(new Color(202,219,243));

JScrollPane spane = new JScrollPane(area,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
spane.setBorder(BorderFactory.createEtchedBorder());

panel.setBackground(new Color(203,222,148));
panel.add(spane);
panel.add(ok);
panel.add(close);

frame.getContentPane().add(panel);
frame.pack();

window.setLocation((int) (t.getScreenSize().getWidth() - STARTING_POS_X),
(int) (t.getScreenSize().getWidth() - STARTING_POS_Y));
window.setContentPane(frame.getContentPane());
window.setBounds(0, 0, 265, 168);
window.setAlwaysOnTop(true);

for (int i = 300; i < 450; i = i + 1) {
window.setLocation(
(int) (t.getScreenSize().getWidth() - STARTING_POS_X),
(int) (t.getScreenSize().getWidth() - i));
window.setVisible(true);
}
}


public static void main(String[] args) throws Exception {
new PopupWindowTest().showMessage("The message goes here");
}
}

Thursday, May 28, 2009

Simple Java Tray Example

I am just putting below a sample code to create a simple tray icon using java awt.
Also I will demonstrate how to show a Error, Warn or Info balloon message and opening a browser on click of the balloon message.

Following is the sample code:

SystemTray tray = SystemTray.getSystemTray();
TrayIcon ti;
PopupMenu menu = null;
menu = new PopupMenu();

MenuItem menuItem = new MenuItem("Quit");
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String s = ((MenuItem) (e.getSource())).getLabel();
if (s.equalsIgnoreCase("Quit") {
System.exit(1);
}
s = null;
}
});
menu.add(menuItem);

Image i = new ImageIcon("imagenage.gif").getImage();
ti = new TrayIcon(i, "Tool Tip to be displayed on mouse hover",
menu);


This should create a tray icon with the selected image. The tool tip message is displayed whenever the mouse hovers over the tray icon. On click of the tray icon the Menu created by PopUpMenu shows, in the above code it just shows an exit menu.

Below we will add a balloon message to the tray.


ti.displayMessage("Message Title",
"Actual Message", MessageType.INFO);


Note: The Message Types can be INFO, ERROR or WARNING Or NONE

Lets say we want to open a broswer on click of the balloon message. TO achieve this first we have to add a action listener to the tray icon, as shown below:

ti.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

}
});



Now that we have added an action listener, we will see how to open the browser and browse a site on click of the balloon message. To achieve this, add the following code to the actionPerformed method.


Desktop.getDesktop().browse((new URI("www.google.com"));


Voila Done.


On Second thoughts--- This Tray Icon API is in Java 1.6. Forgot to mention that :)

Wednesday, May 20, 2009

Pictures Which Have a Meaning in Life

Images and Wording thanks to Rajiv Mathew



1957. The first day of Dorothy Counts at the Harry Harding High School in the United States . Counts was one of the first black students admitted in the school, and she was no longer able to stand the harassments after 4 days.



January 12, 1960. A second before the Japanese Socialist Party leader Asanuma was murdered by an opponent student.



1962. A soldier shot by a sniper hangs onto a priest in his last moments.




1963. Thich Quang Duc, the Buddhist priest in Southern Vietnam , burns himself to death protesting the government's torture policy against priests. Thich Quang Dug never made a sound or moved while he was burning.




1965. A mom and her children try to cross the river in South Vietnam in an attempt to run away from the American bombs.



1966. U.S. troops in South Vietnam are dragging a dead Vietcong soldier.



February 1, 1968. South Vietnam police chief Nguyen Ngoc Loan shoots a young man,whom he suspects to be a Viet Cong soldier..



1973. A few seconds before Chile 's elected president Salvador Allende is dead during the coup.



1975. A woman and a girl falling down after the fire escape collapses.



1980. A kid in Uganda about to die of hunger, and a missionary.



February 23, 1981. Colonel Molina ve military police seizes the Parliament building in Spain. The photographer did not expect the scene, and hid the films in his shoe.



1982. Palestinian refugees murdered in Beirut , Lebanon .




1987. A mother in South Korea apologizes and asks for forgiveness for his son who was arrested after attending a protest. He was protesting the alleged manipulations in the general elections.



1989. A young man in China stands before the tanks during protests for democratic reforms.



1992. A mother in Somalia holds the body of her child who died of hunger.



1994. A man who was tortured by the soldiers since he was suspected to have spoken with the Tutsi rebels.



1996. Kids who are shocked by the civil war in Angola .



2001. An Afghani refugee kid's body is being prepared for the funeral in Pakistan .



2002. Soldiers and villagers in IRan are digging graves for the victims of the earthquake.
A kid holds his father's pants before he is buried.




2003. An Iraqi prisoner of war tries to calm down his child.