Results 1 to 19 of 19
- 05-12-2008, 05:52 AM #1
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
- 05-12-2008, 06:00 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Something like this, add an image to GUI or something...
Java Code:Image image = Toolkit.getDefaultToolkit().getImage(your_image_path);
- 05-12-2008, 06:07 AM #3
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
wow, thanks a lot. by the way, is there a simpler way to make an item in the system tray? by the way, i was the one who asked you last week regarding threads that run in an infinite loop. setting the timeout really does well. from 100% CPU it comes down to only 12-50%.
we are making an IM and maybe you have an idea how to make a system tray for that? that is why i asked how to put an image to an Image datatype cause it is a parameter for a certain method creating a system tray. is there a simpler way on doing it? i find it quite difficult to understand all on the net. thanks for the reply anyways. :)
- 05-12-2008, 06:12 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
make an item, or make an image in the system tray? Normally an item mean a system tray pop-up menu item.
How did you do it, because I don't know that ;).
- 05-12-2008, 06:53 AM #5
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
there is this class SystemTray i think in JAVA SE 6. located at java.awt. not quite sure though. here is a link to it on java forums:
New System Tray Functionality in Java SE 6
i dont know if its illegal here posting external links but if its illegal ill just edit it
i'm not that smart to understand it, hehe
- 05-12-2008, 07:01 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First thing is, yes you can post links here in our community. But in good way, don't directed people in wrong way. ;)
Ok, you found a example here. This is a new feature of Java SE6. Before this it's not much easy. :) So now you can go ahead with that example. Where you stuck with.
- 05-12-2008, 08:31 AM #7
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
can you tell whats the problem with this code?
import java.awt.event.*;
import java.awt.*;
import java.awt.Toolkit;
import java.awt.TrayIcon.*;
public class TrayIconDIMS
{
SystemTray systemtray;
java.awt.Image image;
TrayIcon trayIcon;
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
public void TrayIconDIMS()
{
image = Toolkit.getDefaultToolkit().getImage("724793.gif") ;
}
public void showTray()
{
try
{
systemtray = SystemTray.getSystemTray();
System.out.println("System Tray Initialized");
}
catch(java.lang.UnsupportedOperationException e)
{
e.printStackTrace();
System.out.println("Unable to initialize System tray");
}
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
System.out.println("Tray Icon - Mouse clicked!");
}
public void mouseEntered(MouseEvent e) {
System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e) {
System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e) {
System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e) {
System.out.println("Tray Icon - Mouse released!");
}
};
ActionListener exitListener = new ActionListener()
{
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting...");
System.exit(0);
}
};
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Tray Demo", popup);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage("Action Event",
"An Action Event Has Been Performed!",
TrayIcon.MessageType.INFO);
}
};
}
public static void main(String args[])
{
TrayIconDIMS A = new TrayIconDIMS();
A.showTray();
}
}
the error:
init:
deps-jar:
Compiling 1 source file to /home/byuu/NetBeansProjects/testest/build/classes
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:78: cannot find symbol
symbol : constructor TrayIcon(java.awt.Image,java.lang.String,java.awt. PopupMenu)
location: class TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:84: cannot find symbol
symbol : variable MessageType
location: class TrayIcon
TrayIcon.MessageType.INFO);
2 errors
BUILD FAILED (total time: 0 seconds)
- 05-12-2008, 08:44 AM #8
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
Could you try this to your code. =) I think its the same error in handling arrays. In my experience with that, its the declaration. I hope this helps
Java Code:SystemTray systemtray; java.awt.Image image = Toolkit.getDefaultToolkit().getImage("724793.gif") ; TrayIcon trayIcon = new TrayIcon(image); PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Exit");
- 05-12-2008, 09:01 AM #9
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
it still get the same error.
and get another error at your code:
i think the problem is in the TrayIcon declaration or somethin'. thanks for the quick reply.. hope we could sort this one out hehe :)TrayIcon trayIcon = new TrayIcon(image);
im gonna try to compile it on windows. im running on linux,
- 05-12-2008, 09:29 AM #10
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
ohhh. . . Im sorry, Maybe the senior members can help us. =P
- 05-12-2008, 09:42 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You have done it in wrong way, I mean the order you have to take is incorrect. Here is the modified code. Try to get the difference between this and your code.
Java Code:import java.awt.event.*; import java.awt.*; import java.awt.Toolkit; import java.awt.TrayIcon.*; public class TrayIconDIMS { SystemTray systemtray; Image image; TrayIcon trayIcon; PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Exit"); public void TrayIconDIMS() { } public void showTray() { if (SystemTray.isSupported()) { try { systemtray = SystemTray.getSystemTray(); System.out.println("System Tray Initialized"); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray Icon - Mouse clicked!"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { System.out.println("Tray Icon - Mouse pressed!"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); System.exit(0); } }; //defaultItem.addActionListener(exitListener); //popup.add(defaultItem); image = Toolkit.getDefaultToolkit().getImage("RADAR.png"); trayIcon = new TrayIcon(image, "Tray Demo", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("Action Event", "An Action Event Has Been Performed!", TrayIcon.MessageType.INFO); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(exitListener); systemtray.add(trayIcon); } catch (AWTException ex) { System.out.println("Error in icon loading."); } } else { System.out.println("System tray not supported."); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TrayIconDIMS().showTray(); } }); } }
- 05-12-2008, 03:18 PM #12
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
sorry for the late reply. i havent have quite time programming since there was a transport strike here and its hard riding a public transportation. hm, i tried the code, compiled it and says:
the code seems no sign of error in syntax or usage but i dont know if we are missing anything..init:
deps-jar:
Compiling 1 source file to /home/byuu/NetBeansProjects/testest/build/classes
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:56: cannot find symbol
symbol : constructor TrayIcon(java.awt.Image,java.lang.String,java.awt. PopupMenu)
location: class TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:60: cannot find symbol
symbol : variable MessageType
location: class TrayIcon
trayIcon.displayMessage("Action Event", "An Action Event Has Been Performed!", TrayIcon.MessageType.INFO);
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:64: cannot find symbol
symbol : method setImageAutoSize(boolean)
location: class TrayIcon
trayIcon.setImageAutoSize(true);
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:65: cannot find symbol
symbol : method addActionListener(java.awt.event.ActionListener)
location: class TrayIcon
trayIcon.addActionListener(exitListener);
/home/byuu/NetBeansProjects/testest/src/TrayIconDIMS.java:66: add(java.awt.TrayIcon) in java.awt.SystemTray cannot be applied to (TrayIcon)
systemtray.add(trayIcon);
5 errors
BUILD FAILED (total time: 0 seconds)
- 05-12-2008, 11:39 PM #13
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
ney, i kinda fixed it. it displays a trayicon on the system tray although empty. the problem i son the imports. i took away the
import java.awt.TrayIcon
and just declared the whole thing on instances, method calls of class TrayIcon here is the code, just thinking i could share it here, i don't know what's the difference but it worked anyway, :)
import java.awt.event.*;
import java.awt.*;
import java.awt.Toolkit;
//import java.awt.TrayIcon.*;
public class TrayIconDIMS
{
SystemTray systemtray;
Image image;
java.awt.TrayIcon trayIcon;
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
public void TrayIconDIMS() {
}
public void showTray() {
if (SystemTray.isSupported()) {
try {
systemtray = SystemTray.getSystemTray();
System.out.println("System Tray Initialized");
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
System.out.println("Tray Icon - Mouse clicked!");
}
public void mouseEntered(MouseEvent e) {
System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e) {
System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e) {
System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e) {
System.out.println("Tray Icon - Mouse released!");
}
};
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting...");
System.exit(0);
}
};
//defaultItem.addActionListener(exitListener);
//popup.add(defaultItem);
image = Toolkit.getDefaultToolkit().getImage("RADAR.png");
trayIcon = new java.awt.TrayIcon(image, "Tray Demo", popup);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage("Action Event", "An Action Event Has Been Performed!", java.awt.TrayIcon.MessageType.INFO);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(exitListener);
systemtray.add(trayIcon);
}
catch (AWTException ex) {
ex.printStackTrace();
}
}
else {
System.out.println("System tray not supported.");
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TrayIconDIMS().showTray();
}
});
}
}
- 05-13-2008, 03:31 AM #14
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
byuu, Are from the Phillipines? I didnt feel the Transport Strike Yesterday Morning. But later in the afternoon, there are lots of people in the streets.
- 05-13-2008, 03:42 AM #15
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
yes, i'm from davao city, people throw spikes on the roads here, :))
- 05-13-2008, 03:43 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
There is no difference between following two lines.
I think you get the empty try icon, because you don't change the image name. Is it?Java Code:import java.awt.TrayIcon.*; java.awt.TrayIcon trayIcon;
My code is working 100% perfectly. Which JDk version you used. This is support from 1.5 and seems to me you have older version than this.
If you want try this, you can see four import statements in my original code. Remove all of them and add only these two.
Still my code working fine. Still you get the error, you used older version of JDK.Java Code:import java.awt.event.*; import java.awt.*;
- 05-13-2008, 04:00 AM #17
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
The Strike wasnt succesful like before. Luckily i used the Train.
Im from Makati. Nice to meet you sir byuu.
- 05-13-2008, 04:04 AM #18
Member
- Join Date
- May 2008
- Posts
- 15
- Rep Power
- 0
yes mine is working on now. by the way i am using jdk 1.6 maybe java versions matter.. im not sure though
....
yes, nice to meet you too. :)The Strike wasnt succesful like before. Luckily i used the Train.
Im from Makati. Nice to meet you sir byuu.Last edited by byuu; 05-13-2008 at 04:07 AM. Reason: avoid double posting
- 05-13-2008, 04:10 AM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, if you solved the question please mark thread solved.
And also don't make chit-chats on a thread. You have separate forum for that, just do to the forum lobby. :)
Similar Threads
-
creating image using java
By mmahesh_mca in forum New To JavaReplies: 1Last Post: 04-26-2008, 11:23 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
Label image Question
By Soda in forum New To JavaReplies: 3Last Post: 12-10-2007, 03:38 PM -
Background image in java
By toby in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 07:15 AM -
Java Image Album 1.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-04-2007, 07:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks