|
Hi everybody !
Im now using TrayIcon . The tooltip message display two caption and the image belong to Message Type as bellow.
-Title :String
-Message :String.
-MessageType:INFO,WARNING,ERROR,NONE.
I now want to dis play the tooltip message with two caption and the Icon image that i specify the path as bellow:
-Title :String
-Message :String.
-IconImage : IconImage or path of the image.
Can anybody help me.
Thanks very much !
Best regards !
|
|
|
|
|
In short if the TrayIcon class was a JComponent then you can simply apply html tags to it. Therefore, to simulate what you need I will use the jdic.jar from https://jdic.dev.java.net/servlets/ProjectDocumentList?expandFolder=4183&folderID=5497.
import javax.swing.*;
import org.jdesktop.jdic.tray.*;
import java.awt.BorderLayout;
import java.awt.event.*;
public class SystemTrayDemo extends JFrame
{
public TrayIcon trayIcon;
public JDialog dialog;
public SystemTrayDemo()
{
JPopupMenu menu = new JPopupMenu("Menu");
JMenuItem menuItem1 = new JMenuItem("Menu1");
menu.add(menuItem1);
JMenuItem menuItem2 = new JMenuItem("Menu2");
menu.add(menuItem2);
JMenuItem menuItem3 = new JMenuItem("Menu3");
menu.add(menuItem3);
JMenuItem menuItem4 = new JMenuItem("Exit");
menu.add(menuItem4);
menuItem4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
});
ImageIcon icon = new ImageIcon("middle.gif");
trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
SystemTray tray = SystemTray.getDefaultSystemTray();
tray.addTrayIcon(trayIcon);
trayIcon.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dialog = new JDialog();
dialog.add(new JLabel("Title"), BorderLayout.NORTH);
dialog.add(new JLabel("Message"), BorderLayout.CENTER);
dialog.add(new JLabel(new ImageIcon("middle.gif")),BorderLayout.SOUTH);
dialog.setLocation(trayIcon.getLocationOnScreen().x - 50,trayIcon.getLocationOnScreen().y - 105);
dialog.setVisible(true);
dialog.setSize(100, 100);
dialog.setResizable(false);
dialog.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
dialog.dispose();
}
});
}
});
}
public static void main(String[] args)
{
new SystemTrayDemo();
}
}
The presentation of it is close to aero peek in windows 7.
Hope this helps.
Regards
|
|
|
|
|
Hi !
I think you didn't understand my question.
I want to display the IconImage on the top-left of the title .
For example,
trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
must be change to
trayIcon = new TrayIcon(icon, "<img src="image.gif">Hello System Tray",menu);
if we can use html tags in our code !
Thanks anyways !
Can anybody help me ?
Best regards !
|
|
|
|
|
I understood your question, if you read my first line "If the trayicon class was a Jcomponent then we can use html tags". You can display (as a balloon) the message type error,info,etc... use these in place of the dialog code depending on type:
trayIcon.displayMessage("Title", "Message", trayIcon.INFO_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.NONE_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.WARNING_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.ERROR_MESSAGE_TYPE);
otherwise what your asking can only be done if you write your own package.
Regards
|
|
|
|
|
If using a JDialog or JFrame or JPanel to display an image(instead of the tooltip of TrayIcon) i think it is very simple and i didn't post my question.
I posted this question because i saw the "beautiful tooltip" of trayIcon of windowXP "your computer might be at risk". The Iconimage of the tooltip is not in (WARNING,INFO,ERROR,NONE) images.
I'm waiting for a solution for this because Microsoft did it !
Any other ideas ?
Best regards !
modified on Friday, September 11, 2009 12:42 AM
|
|
|
|
|
I was cruising around to see if their is any third party packages that can do what your asking and I stumbled upon an article on codeproject.com but its not in Java its using windows pressentation foundation but it does exaclty what you ask:
http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx
All you need now is to get Visual C# express and get the risk icon (what i did in windows 7 rc go to windows firewall and click on turn of firewall you will get the red x snap it using the snap tool and go to photoshop to do some editing and you can then save it as 16 x 16 icon and name it Inactive.ico) then copy it and place it in the c:\...wpf-notifyicon\Sample Project\Icons folder, then rebuild the code and run, you will find at the bottom right corner custom notification message.
Hope this helps. I will try to ask sun about it but you said it your self Microsoft did it with their language not Java
Regards
|
|
|
|
|
Thank you for a clear solution from Microsoft Tech.
Im Still waiting for your "asking result" from Sun.
Best regards !
|
|
|
|
|
i want to develop a software by which once can remotely access one system, the program should be such that is should be platform independent, as in, a apple system can remote login a ubuntu system and the controls for the mouse, screen and board is transferred.
Also let me know, how to enable which port in that case, as port is dependent on the operating system as in 3389 for windows, 5900 for ubuntu i guess, any pointers for that.
Please let me know.
Regards
Ashish
|
|
|
|
|
These will do the job
http://sourceforge.net/projects/jrdesktop/
https://jxta-remote-desktop.dev.java.net/
http://jrdesktop.sourceforge.net/
http://www.codeproject.com/KB/IP/RemoteAdminJava.aspx
http://kenai.com/projects/jrdesktop
http://java-hush.sourceforge.net/prot-1.5.html which is from http://java-hush.sourceforge.net/
They have all the resources you need.
Good Luck
|
|
|
|
|
|
0. Remove you're e-mail address - it's a big invite to the Vikings.
1. Have you tried some diagnostics? Put some logging into your code and find out where things are going Lady Gaga, then post a nice little snippet to show what's gone wrong with an explanation of what you tried.
2. ??
3. Profit.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Sending an Email in Java (Servlet)
Prerequisites:
1. Java Mail API (mail.jar)
2. activation.jar
3. HTML Form (Optional)
4. Servlet or JSP (to send the email)
Steps:
1. Download and install JDK6U16
2. Download Apache Tomcat
3. Download Eclipse
4. In Eclipse, make sure to add the apache server first
5. Create a dynamic web project
6. Under the WEB-INF create a folder called lib and paste mail.jar and activation.jar
7. Create a jsp and call it index.jsp
8. Create a servlet and call it sendMail
9. Create a class called MyPasswordAuthenticator (will act as authentication or you can use the code inside the sendMail as you like)
10. Create two jsps (success and error)
11. Create a css file called style
index.jsp Code:
<html>
<head>
<title>Sending email</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<center>
<form action="sendMail" method="get">
<table>
<tr>
<td>From</td>
<td><input type="text" name="from"></td>
</tr>
<tr>
<tr>
<td>To</td>
<td><input type="text" name="to"></td>
</tr>
<tr>
<td>Subject</td>
<td><input type="text" name="subject"></td>
</tr>
<tr>
<td>Message</td>
<td><textarea cols="25" rows="8" name="message"></textarea></td>
</tr>
</table>
<br>
<input type="submit" value="submit">
</form>
</center>
</body>
</html>
style.css
* { font-size: 12px; font-family: Verdana }
input, textarea { border: 1px solid #ccc }
textarea { text-align:left}
table { margin-top: 10% }
.error { margin-top: 10%; border: 1px dotted #db1f1f; width: 250px }
.msg { margin-top: 10%; border: 1px dotted #ccc; width: 250px }
sendMail Servlet
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class sendMail extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
{
String username = "your gmail account";
String password = "your gmail password";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.starttls.enable", "true");
Session session = null;
if (username != null && password != null)
{
props.put("mail.smtp.auth", "true");
session = Session.getInstance(props, new MyPasswordAuthenticator(username, password));
}
else
{
session = Session.getDefaultInstance(props, null);
}
MimeMessage message = new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(req.getParameter("from")));
InternetAddress[] address = InternetAddress.parse(req.getParameter("to"), false);
message.setRecipients(Message.RecipientType.TO, address);
message.setSubject(req.getParameter("subject"));
message.setText(req.getParameter("message"));
Transport.send(message);
RequestDispatcher d = req.getRequestDispatcher("success.jsp");
d.forward(req, resp);
}
catch (Exception e)
{
try
{
RequestDispatcher d = req.getRequestDispatcher("error.jsp");
d.forward(req, resp);
}
catch (Exception e2) {}
}
}
}
MyPasswordAuthenticator
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
class MyPasswordAuthenticator extends Authenticator
{
String user;
String pw;
public MyPasswordAuthenticator (String username, String password)
{
super();
this.user = username;
this.pw = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user, pw);
}
}
success.jsp
<html>
<head>
<title>Message</title>
</head>
<body>
<center>
<div class="msg">
<h2>Message</h2>
<p>
Email sent
</p>
</div>
</center>
</body>
</html>
error.jsp
<html>
<head>
<title>Error</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<center>
<div class="error">
<h2>Error</h2>
<p>
Message: <%= request.getAttribute("ErrorMessage") %>
</p>
</div>
</center>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SendingEmail</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>sendMail</display-name>
<servlet-name>sendMail</servlet-name>
<servlet-class>sendMail</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sendMail</servlet-name>
<url-pattern>/sendMail</url-pattern>
</servlet-mapping>
</web-app>
Make sure to put your gmail username and password in sendMail servlet
Next run index.jsp
Good luck
modified on Tuesday, September 8, 2009 7:35 PM
|
|
|
|
|
Thanks Member 4277480 for ur reply
SIR i deployed your coding in NET-BEANS.
The files like
index.jsp
error.jsp
success.jsp
style.css
MyPasswordAuthenticator.java
sendMail.java
was easily uploded into it but
in case of mail.jar & activation.jar
i downloaded the javamail-1.4.2 and jaf-1_1_1
rar files from sun.com and then there is a confusion on by which
name they are to be import to source library..
i gave the names javamail-1.4.2 and jaf-1_1_1 and give path to jar files....
i also provided the gmail account and password , but i am not able to send the mail.
would you please tell whether you were succeeded in doing it and help me out sir, it is very important for me.
please provide a bit more details
I need your helping hand
please help....
what i think that i haven't configured any smtp server.
Could you please tell what should i do for it...
i think i am missing this thing only
reply soon
modified on Friday, September 11, 2009 5:17 AM
|
|
|
|
|
http://www.mediafire.com/download.php?yygnyhmd1dg
1. Download rar from above.
2. Open it using Eclipse (JDK6U16)
3. When you provide your account make sure its in the format email@gmail.com
All done.
To setup a personal smtp read this guide:
http://www.ehow.com/how_4489548_set-up-smtp-server-windows.html
Good Luck
|
|
|
|
|
hello sir
the link you provide
http://www.mediafire.com/download.php?yygnyhmd1dg
is not working, the rar file is not available..
please look at it
also tell me that, the code you provided me is just sufficient to send message
or i need to configure a smtp server also..
because i am just running your code
please reply soon...
|
|
|
|
|
|
well Member 4277480
i am trying your code but it still not sending them.
Tell me whether i have to configure some smtp settings
to the gmail account which i am using here.
also if possible please send some important screenshot
like when configuring tomcat server.
also tell me what is this program actually doing, is this sending the mails to any client by using my email address in FROM: option.
do i need to configure any port
Please help me this last time...
I am very close to successfully running it..
Please reply with screenshots
|
|
|
|
|
|
hi
how to convert java swings application to java applet
please guide me
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import com.standbysoft.datepicker.JDatePicker;
public class GeneralDemo extends JPanel {
private JDatePicker datePicker;
public GeneralDemo() {
datePicker = new JDatePicker();
setLayout(new GridBagLayout());
add(datePicker, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0));
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("GeneralDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GeneralDemo newContentPane = new GeneralDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
have a nice day
bye
naga
|
|
|
|
|
0. Wrap you code in <PRE> tags, it'll keep it flame-retardent.
1. What have you tried? You have to make an effort for anyone here to help, just asking for code won't be of any use.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Applet Code
import java.applet.*;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import com.standbysoft.component.date.swing.JDatePicker;
public class GeneralDemo_2 extends Applet
{
private JDatePicker datePicker;
public void init()
{
datePicker = new JDatePicker();
setLayout(new GridBagLayout());
add(datePicker, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0));
}
}
HTML Code
<object
code="GeneralDemo_2.class"
type="application/x-java-applet"
archive="jdatepicker.jar"
height="300" width="450"
>
</object>
Make sure you have the jdatepicker.jar in the same location as your .class and html
Good Luck
|
|
|
|
|
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import java.io.*;
public class DateExample extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException {
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<html><head><title>wELCOME TO sERVLET pROGRAMING</title></head>");
pw.println("<body>");
pw.println("Print date and time");
java.util.Date dat=new java.util.Date();
pw.println(dat);
pw.println("</body></html>");
System.out.println("Thnx 4 using this application");
}
}
<servlet>
<servlet-name>hai
<servlet-class>DateExample<
<servlet-mapping>
<servlet-name>hai
<url-pattern>/ServletSample
at the time of deployment iam getting error like this, tell me how to resolve this one.
The requested resource (/ServletSamples/DateExample) is not available.
|
|
|
|
|
A 404 error indicates a WEB/HTML issue rather than a programming bug.
Take a look at your web servers logs. 404 indicates it couldn't find the resource (URI). Is your web.xml properly configured for the servlet?
|
|
|
|
|
Make sure this is in your web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test_1.1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>DateExample</display-name>
<servlet-name>DateExample</servlet-name>
<servlet-class>DateExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DateExample</servlet-name>
<url-pattern>/DateExample</url-pattern>
</servlet-mapping>
</web-app>
Your code works fine
Good luck
|
|
|
|
|
Hi All,
I am very new to this forum. And I have very little knowledge in java. I want to create one key logger application. Please suggest me which language is best whether java or c++. And I dont where to start and how to start. Please people you have any ideas share with me.
|
|
|
|