Product Home

Usage

Demo

Download

Purchase

Support

Feedback

 

Demo 5: Taskbar Tray Icon and EventLog

Function: Convert JAR archive into Executive.


Part 1: Code Example

1. Download the interface code and compile:

Download: [Interface Download] - 4kb


2. Code D:\test\HelloTray.java:

/*
 * Created on 2007-2-5
 */

package test;

import java.io.*;

import com.regexlab.j2e.*;

/**
 * @author sswater shi
 */

public class HelloTray implements SystemTrayCallback
{
    public static void main(String[] args) throws Exception
    {
        System.out.println("Hello World");
        System.out.println();

        // arguments
        if(args.length > 0) dump_args(args);
       
        // SystemTray
        SystemTray tray98 = new SystemTray(1, "hello, simple tip");
        SystemTray tray2k = new SystemTray(1, "hello", "win 2k info",
            "title", SystemTray.INFOTYPE_INFO);
       
        SystemTray.setSystemTrayCallback(new HelloTray());
       
        // EventLog
        EventLog log = new EventLog("Log from Java");
       
        try
        {
            System.out.println("Testing:\n 1 - test system tray,\n 2 - hide trays,\n 3 - test eventlog,\n 4 - exit");
            BufferedReader in = new BufferedReader(
                new
InputStreamReader(System.in));
            String line = null;
            
            while((line = in.readLine()) != null)
            {
                switch(line.charAt(0))
                {
                case '1':
                    tray98.Show();
                    tray2k.Show();
                    System.out.println("Icon shown.");
                    break;

                case '2':
                    tray98.Hide();
                    tray2k.Hide();
                    System.out.println("Icon hidden.");
                    break;
                    
                case '3':
                    log.reportEvent(EventLog.INFORMATION,
                        (short)0, 1, "msg");
                    System.out.println("New log reported.");
                    break;
                    
                case '4':
                    System.out.println("exiting");
                    return;
                }
            }
        }
        finally
        {
            tray98.Hide();
            tray2k.Hide();
        }
    }
   
    protected static void dump_args(String[] args)
    {
        System.out.println("You have typed " +
            args.length + " arguments:");
        for(int i=0; i<args.length; i++)
        {
            System.out.println(i + " - " + args[i]);
        }
    }

    public void OnMouseClick(SystemTray tray, int mouseEvent)
    {
        if(mouseEvent == SystemTray.LEFT_CLICK)
            System.out.println("left clicked");
    }
}

Part 2: Compile and Run

1. Download the latest Jar2Exe Wizard 1.7 .

2. When creating exe, let 'event log' and 'system tray' checked:

3. Download the program and result exe in this demo:

[SysTrayDemo.zip] - 34kb


More Demos:

Demo 1: How to generate a CONSOLE application in java?

Demo 2: How to generate a Windows GUI application in java?

Demo 3: How to build and create a Window NT Service in java?

Demo 4: Window NT Service supports PAUSE/CONTINUE.

 

 

RegExLab.com © 2005 - All Rights Reserved