I've looked on some other posts about this, but didn't really understand much from it.
I've made a program that works like a server while capturing different pictures of the screen. Now, i'd like the program to just be active in the background - like the programs that appear under hidden icons. Programs that are not directly shown at the bottom taskbar. Do i need to add some specific code inside my java program when i execute it to a jar file? Or do i need to create the project some other way?
I hope this was enough explanation - Thanks in advance
Put you program in this directory: %appdata%\Microsoft\Windows\Start Menu\Programs\Startup Everything in there will be executed at startup.
To run a Java program, whether an applet or an application, the JVM is then used to interpret and execute the bytecode. The Java SE comes in two parts, a runtime program, called the Java Runtime Environment (JRE) and a development package, called the Software Development Kit (SDK).
To sum it up, Java, when compiled, creates a bytecode (. class file), which can be run in any machine which supports JVM. So once compiled it doesn't require re-compilation at every machine it runs, JVM converts the bytecode to be understood by the underlying hardware.
Something super simple that I got from Here. All I did was add an exit on click.
Code
public static void main (String [] args) {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
Image image = Toolkit.getDefaultToolkit().getImage("MY/PATH/TO_IMAGE");
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(image, "MY PROGRAM NAME", popup);
final SystemTray tray = SystemTray.getSystemTray();
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}
}
Just get any image and add it to your resources or wherever you keep your images and make a path to it.
You can achieve this by using the java.awt.SystemTray
API in combination with Java Swing API.
Refer this documentation from Oracle:
Oracle Java documentation for System Tray API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With