|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-12-2008, 07:52 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
|
[SOLVED] Question about java.awt.image
how do you simply put an image(gif format) to an Image datatype?
example:
import java.awt.image.*;
Image i = ?????
how do you do that?
|
|

05-12-2008, 08:00 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
Something like this, add an image to GUI or something...
Image image = Toolkit.getDefaultToolkit().getImage(your_image_path);
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-12-2008, 08:07 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
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, 08:12 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
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 .
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-12-2008, 08:53 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
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, 09:01 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-12-2008, 10:31 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
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, 10:44 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
|
|
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
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, 11:01 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
it still get the same error.
and get another error at your code:
TrayIcon trayIcon = new TrayIcon(image);
i think the problem is in the TrayIcon declaration or somethin'. thanks for the quick reply.. hope we could sort this one out hehe
im gonna try to compile it on windows. im running on linux,
|
|

05-12-2008, 11:29 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
|
|
|
ohhh. . . Im sorry, Maybe the senior members can help us. =P
|
|

05-12-2008, 11:42 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
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.
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();
}
});
}
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-12-2008, 05:18 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
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:
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)
the code seems no sign of error in syntax or usage but i dont know if we are missing anything..
|
|

05-13-2008, 01:39 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
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, 05:31 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
|
|
|
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, 05:42 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
yes, i'm from davao city, people throw spikes on the roads here,  )
|
|

05-13-2008, 05:43 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
Originally Posted by byuu
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, 
There is no difference between following two lines.
import java.awt.TrayIcon.*;
java.awt.TrayIcon trayIcon;
I think you get the empty try icon, because you don't change the image name. Is it?
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.
import java.awt.event.*;
import java.awt.*;
Still my code working fine. Still you get the error, you used older version of JDK.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 06:00 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
|
|
|
The Strike wasnt succesful like before. Luckily i used the Train.
Im from Makati. Nice to meet you sir byuu.
|
|

05-13-2008, 06:04 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 15
|
|
yes mine is working on now. by the way i am using jdk 1.6 maybe java versions matter.. im not sure though
....
The Strike wasnt succesful like before. Luckily i used the Train.
Im from Makati. Nice to meet you sir byuu.
yes, nice to meet you too. 
Last edited by byuu : 05-13-2008 at 06:07 AM.
Reason: avoid double posting
|
|

05-13-2008, 06:10 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,592
|
|
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. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
|
| | |