Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Java System Tray Application using Visual Basic

0.00/5 (No votes)
2 Oct 2002 1  
This is Simple Java System Tray Application.. This Works only in Windows Environment. No Need For JNI.

Sample Image - SystemTray.gif

Introduction

Hi Guys, This is my third article in Codeproject. I hava already posted
SsTab Control in Java
and Java Chat Application with great customizable GUI. I hope this
will also useful for all java developers.
This is Simple Java System Tray Application.. This Works
only in Windows Environment. No Need For JNI.

Description

Here, I am using VB Api for putting java application in
System Tray.

This is Vb Code For System Tray

	Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias 
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Private Const WM_MOUSEMOVE = &H200 Private Const NIF_ICON = &H2 Private Const NIF_MESSAGE = &H1 Private Const NIF_TIP = &H4 Private Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const MAX_TOOLTIP As Integer = 64 Private Type NOTIFYICONDATA cbSize As Long hwnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * MAX_TOOLTIP End Type Private nfIconData As NOTIFYICONDATA .....

This is the Vb code for Killing System Tray Application.

	Private Const WM_CLOSE = &H10
	Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
	Private Declare Function FindWindow Lib "user32" Alias "
FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

	Private Sub Form_Load()
	    PostMessage FindWindow(vbNullString, "SystemTray"), WM_CLOSE, ByVal 0, ByVal 0
	End
End Sub

This is Vb Api for Hiding window from the task.

	Private Declare Function ShowWindow Lib "user32" 
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias 
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const SW_HIDE = 0

Private Sub Form_Load()
    WindowHandle = FindWindow(vbNullString, "SystemTray In Java")
    ShowWindow WindowHandle, SW_HIDE
    End
End Sub

SO, after finishing these all VB part, we have to make exe files.
afer that, using process and runtime class,
we have to call these exe's.

The Main Step in this System Tray Application is "Window Title"
Here, i am using "SystemTray In Java" as a Window Title.
In Out Vb Program, we have to use this window tiltle for
Finding ,hiding,and showing window.

Here, this is the Java Code for System Tray Application.

/**********Quitting System Tray****************/
try {
   process = Runtime.getRuntime().exec("data/SystemTrayKill.exe");
}catch(IOException _IoExc) { }	
				
dispose();
System.exit(0);
}
});
setLayout(new BorderLayout());
setSize(400, 200);
setTitle("SystemTray In Java"); 
Label LblTray = new Label("System Tray Demo in Java !",1);
LblTray.setBackground(Color.black);
LblTray.setForeground(Color.white);
LblTray.setFont(new Font("Arial",1,25));
add("North",LblTray);
CmdTray = new Button("Go To System Tray");
CmdTray.addActionListener(this);
add("Center",CmdTray);
Label LblDevelop = new Label("Developed By Jeeva S (vavjeeva@yahoo.com)",1);
LblDevelop.setBackground(Color.black);
LblDevelop.setForeground(Color.white);
LblDevelop.setFont(new Font("Arial",1,15));
add("South",LblDevelop);
				
/**********Loading System Tray****************/
try {
   process = Runtime.getRuntime().exec("data/SystemTray.exe");
}catch(IOException _IoExc) { }
show();		
}
	
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource().equals(CmdTray))
{
/**********Hiding Window****************/
try {
  process = Runtime.getRuntime().exec("data/SystemTrayHide.exe");				
}catch(IOException _IoExc) { }
}	
}	
}

Conclusion

I hope this wil help u guys.. If you have any doupts contact me
My mail id is
vavjeeva@yahoo.com
Have A Nice Day.



Jeeva S



License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here