Showing posts with label Java Tricks. Show all posts
Showing posts with label Java Tricks. Show all posts

Question: How can I change the default icon on application window (java cup) to my own?

window.setIconImage(Toolkit.getDefaultToolkit().getImage("image.gif"));

This saved me 1 GB of RAM! I decreased continuous memory leakage from 1 GB to 40 Mb with 25 tabs opened during two weeks

All Java developers know that development of Java2SE, Java EE 5 is MUCH, MUCHmemory demanding process.
We used to suffer from memory absence on our Work Stations and in coffee room usually blame our chiefs and IT support department: "You know, we need more memory to be more effective with Java development, but our greedy, stupid chief(s) do not understand this fact due to the fact that they are chiefs ".
Quite right... But are you so perfect, that you have a right to blame anybody else in memory disappearance, but not yourself? Yesterday i noticed that something goes wrong on my PC.... Even having open just a few applications I noticed, that memory consumption exceeded 2.5 GB! I had 2 GB RAM, but something in my windows environment still was hungry.
Guess what? Probably you are right - Firefox, the browser most Java developers prefer... I had not restarted my browser last two weeks and had ~25 tabs opened... Resulted in more that 1 GB of memory leakage...
Fortunatelly, I pretty fast extracted all the solutions for Firefox optimisations from my bookmarks - I had no time to start to use them before.

The Calculator

In case you are not in a mood to use the standard windows calculator and want your browser to do the dirty job for you, use this code.

javascript: alert(34343+3434-222);

You can change the numbers according to your choice and also try creative complex equations. Just put your arithmetic into javascript: alert( );

Changing Cursors in Java Swing

OK then. Let’s get started. This tutorial will teach you how to change the cursor icon which is used to display the location of the mouse, to one of the other predefined Icons in the Java Abstract Window Toolkit (and hence, Java Swing).
You change the cursor using