Changing Desktop Icon for Java Application - java

I wish to thank you in advance for taking the time to read my question, and I would greatly appreciate any comments, answers, insights, techniques and critiques that you may be able to provide.
I'm looking for a useful method for changing the desktop icon for a Java application. I've looked into this for a few days now, but am not finding an accurate result.
Before you mark this down and call it a duplicate, I have read: How do I change the default application icon in Java? to others who asked this question), but this does not address my specific problem. I know that their method utilizes a url location instead of an import, but I am trying to learn how to use this with the import(if that is, in fact, possible). When I attempt to use their method for changing by source location. Besides that, the url example doesn't seem to work for a file stored on the computer. I get an "uncaught error" message when I attempt to run it.
I use the following format to declare an image that I have imported into NetBeans:
Image image = new ImageIcon("imported.png").getImage();
frame.setIconImage(image);
Now this works fine for the icon that displays in the toolbar and it also appears in the upper left-hand corner of the frame, but I still have the Java coffee-cup as the icon for the application when I clean and build it.
For additional resources to the code that I am using to attempt this:
import java.awt.Image;
import javax.swing.*;
public class Check {
JFrame frame;
public static void main(String[] args) {
new Check().go();
}
private void go() {
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image image = new ImageIcon("owl.gif").getImage();
frame.setIconImage(image);
frame.setVisible(true);
frame.setSize(300, 300);
}
}
The "owl.gif" bit is what I imported into NetBeans by click and drag method (as described in one of the books that I read that focused on NetBeans).
I'm looking for a way to make a file that I already have saved on my computer the desktop icon for my application after it is built.

For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start1. JWS works on Windows, OS X & *nix.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
The 'desktop integration' will use the image identified in the launch file as the desktop or menu item icon.

Related

Changing the default icon in Netbeans' native deployment feature for Java apps

I know the question is very long, but in a nutshell it's just that. As you know Netbeans has a feature with the help of inno setup that allows the creation of .exe installers of Java applications. The problem is that I would like to change the default icon it has (a grey java icon) for a custom one.
I have searched a lot through both Stack and Google and I haven't found anything. The closest it got is to change it via Launch4j. The thing is if it is possible to do it within Netbeans.
Furthermore, I was wondering if there is a possibility to add several languages to the installer and some other features like the creation of a desktop icon. I guess if the option exists it would be in the same place as the change-icon... but I am completely lost regarding this issue.

Can you make an uncloseable, unleavable, Java application?

Is there a way to make sure that a user cannot close or leave my Swing application? I've tried to make it fullscreen, but you can still Alt-Tab away from it—and besides, that doesn't work well when you decide to use JOptionPane's dialogs.
So, is there any way to make a user use only this one Java program on a device?
Edit: Some people wonder about the purpose. The application is supposed to be sorta "embedded" into the handheld device (which runs under Windows), so the users of the device will use it as we intend it to be used—for example, that they won't play Freecells or do something worse instead of doing the actual work. Have you seen ticketing kiosks? They are locked down pretty well, you can't just close their big flashy GUI and get to the Windows desktop!
Okay #Daniel showed you how to make a Java app un-closeable (+1 to him) by calling:
JFrame#setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
on the JFrame instance.
To make sure you cant leave it i.e by pressing CTRL+ALT+DEL and ALT+TAB etc you may want to do this (applies to windows only):
1) Disable TaskManager/CTRL+ALT+DEL by:
Setting registry key:
HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/System/DisableTaskMgr = 1
via reg script or cmd.exe.
2) To disable all shortcuts together like ALT+TAB etc see here (Download/use the *.reg script and execute it via cmd).
Uncloseable yes, you can use setDefaultCloseOperation(); and pass it JFrame.DO_NOTHING_ON_CLOSE
Example:
import javax.swing.*;
import java.awt.*;
class app extends JFrame {
app(String title, int height, int width)
{
super (title);
setSize(width, height);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setVisible(true);
}
}
class program {
public static void main(String[] args) {
app myApp = new app("Hello", 350, 750);
}
}
We do something similar with a POS application, but we cheat a little bit. While making use of Full Screen helps a lot, we found users could STILL exit the application.
In the end, we created a Windows Service (yes, we run on Windows) that automatically RESTARTS as soon as it's closed. So, you can see the Windows desktop (we removed the icons) for a split second, but then the app pops up again. The benefit of this is also that we can update the JAR file remotely, from the intranet, and all the users need to do is push a button that closes the system, it restarts automatically and is updated. We wanted to use WebStart, but had problems integrating it with our wrapper.
The wrapper itself is a Python application that just starts the JVM and application, compiled to an EXE. Simple, but effective.
The net effect is a closable application that will automatically start itself again. Good enough for our use where we need to user to be able to do one thing and one thing only. Giving the startup credentials for the application Admin privileges, and the users just a normal account, took care of the pesky 'alt-ctrl-del' users as well. You can't kill a process that's got higher access rights than yourself.
If you don't feel like writing your own wrapper, give http://wrapper.tanukisoftware.com/doc/english/product-overview.html a whirl, it looks like a brilliant product.
You can catch pretty much any keystrokes you like (and have them ignored) in your app, so Alt-Tab can be fixed. The one key combination that an application can never (ish) handle itself, is the Ctrl+Alt+Delete, which is hooked into the kernel in many operating systems for security reasons. As a side note: this is why many login screens ask you to hit C+A+D before entering your username and password.
You can make a maximized window that can't be unmaximized or closed. You'd also have to trap certain keystrokes such as CTRL+SHIFT+ESCAPE, ALT+TAB, WIN+[anything], various Fn keys, and you'd have to do something to prevent CTRL+ALT+DELETE from working (Either from showing the task manager or from bringing up the blue options screen in windows vista or 7.
I believe there are windows API calls that can change the behavior of CTRL+ALT+DELETE somehow but have no idea what they are. A good place to investigate would be Sysinternals Process Explorer, which has the functionality to replace the task manager. Figure out how it does this, then replicate it.

Run a non-applet .jar game on a browser

I am a beginner in java game programming. I have developed a simple java game and obtained a .jar file of it. It is not an applet. I would like to run it on a browser. Is that possible? How can I achieve that?
Assuming your jar's main class simply opens a JFrame to show its contents, you can build a wrapper applet class which simply invokes it, like this:
public class WrapperApplet extends Applet {
public void start() {
new Thread("application main Thread") {
public void run() { runApplication(); }
}.start();
}
private void runApplication() {
my.Application.main(new String[0]);
}
}
If you want it nicer, have the applet show a button and start the main method only after the button is clicked.
If you want to embed a java application in a web page, you need it to be in applet form. It's not that difficult to convert them, see this link for a bit of help.
It's possible with Java Web Start. From the Wikipedia article:
Web Start can also launch unmodified applets that are packaged inside .jar files, by writing the appropriate JNLP file. This file can also pass the applet parameters. Such applets also run in a separate frame. Applet launcher may not support some specific cases like loading class as resource." The same article mentions some of the problems with applets "Web Start has an advantage over applets in that it overcomes many compatibility problems with browsers' Java plugins and different JVM versions.
This SO question explains some of the tradeoffs on Applets v. JWS... In my opinion, if you expect a lot of people on different types of systems to use your application, or if it uses a fair amount of memory (likely with a game), JWS is better.

Is there a way to find out the class of form using eclipse?

I am working on a large undocumented application written in swing/awt. I have to make changes to it and i need to find out what class a form belongs to when i open it. Is there a way to do this via eclipse?
For example: I open the application and to do something with the app such that some frame opens. How do i find out the class of that form? Can this be done through eclipse?
I know i can comb trough the logic but this is a very laborious and largely ineffective process, chunks of the logic are either in jar files or obfuscated.
Thanks.
For figuring out how a given Swing frame is put together, I have found Swing Explorer to be VERY helpful.
https://swingexplorer.dev.java.net/
After installing the Eclipse plugin, note that you need to "Run as ->" to invoke Swing Explorer properly.
I don't know if this is what you need, but maybe you should try searching(MainMenu-->Search) your entire Project for the specific Window title (String) that comes up with this particular window.

Turn Java App into Windows Screensaver

I wrote a program that solves mazes with depth-first search. I was wondering how to turn this Java program into a Screensaver application? Is there a way that Windows 7 starts my app when the screensaver would normally be activated?
A Windows screen saver is just program that accepts certain command line arguments. So in order to have your program be runnable as a screen saver you must code it to accept those arguments.
Next you will probably want your screen saver to run in full screen mode. This is very simple to do in Java as the example below shows:
public final class ScreenSaver {
public static final void main(final String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
final JFrame screenSaverFrame = new JFrame();
screenSaverFrame.setDefaultCloseOperation(
WindowConstants.EXIT_ON_CLOSE);
screenSaverFrame.setUndecorated(true);
screenSaverFrame.setResizable(false);
screenSaverFrame.add(new JLabel("This is a Java Screensaver!",
SwingConstants.CENTER), BorderLayout.CENTER);
screenSaverFrame.validate();
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.setFullScreenWindow(screenSaverFrame);
}
}
Finally you will need to make your Java program into a Windows executable using something like Launch4j and give it .scr extension.
I have never used this but it might be the place to start. Screen Saver API.
The link to the screensaver SDK seems to be broken at the moment so I am linking to the index page: JDIC. When they fix their link I'll adjust this.
Windows screensavers are just exe files that accept certain command-line arguments, detailed here.
If you can compile your java app into an exe (I don't use java much any more so I'm not sure what tools exist), then rename it to .scr, that would do it.
Or it might be enough just to make a .bat file like:
#echo off
java myProg.class %1
.. And rename it to .scr.
I would look into the SaverBeans API for creating screen savers in Java.
Use the JScreenSaver library.JScreenSaver is the middleware to make a screen saver for Windows in Java language
One of the alternative to this approach is the new JavaFX. You can create fancy screen saver in the same way you do it in Swing. On top of that you get *.exe file quite easily using NetBeans.

Categories