当前位置: 技术问答>java相关
请问大虾:如何使鼠标点击一个JLable就发邮件
来源: 互联网 发布时间:2015-04-12
本文导语: 如: 请联系作者 鼠标over“作者”,会产生超级连接的样子,然后点击会自动调用发邮件程序 请教请教,详细详细 | // java mail package http://java.sun.com/products/javamail/index.html //java ...
如:
请联系作者
鼠标over“作者”,会产生超级连接的样子,然后点击会自动调用发邮件程序
请教请教,详细详细
请联系作者
鼠标over“作者”,会产生超级连接的样子,然后点击会自动调用发邮件程序
请教请教,详细详细
|
// java mail package http://java.sun.com/products/javamail/index.html
//java mail depends on http://java.sun.com/products/javabeans/glasgow/jaf.html
//Set your CLASSPATH to include the "mail.jar" file obtained from
// the download, as well as the current directory.
//
// Assuming you unzipped javamail-1_2.zip in c:download the
// following would work:
//
// set CLASSPATH=%CLASSPATH%;c:downloadjavamail-1.2mail.jar;.
//
// Also include the "activation.jar" file that you obtained from
// downloading the JavaBeans Activation Framework, in your CLASSPATH.
//
// set CLASSPATH=%CLASSPATH%;c:downloadactivationactivation.jar
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mail extends JFrame
{
JLabel jlSendMail = new JLabel("Send Mail");
public Mail()
{
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlSendMail);
jlSendMail.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
try{
String host = "smtp.21cn.com";//"Mail Server in your Company";
String from = "aaaa@21cn.com";//"From Email";
String to = "bbbb@21cn.com";//"To Email";
Properties props = new Properties();
Session session;
//Store store;
Transport transport;
props.put("mail.smtp.host", host);
session = Session.getInstance(props, null);
//session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from,"Ahmad"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to,"Ahmadwa"));
message.setSubject("First");
//message.setSentDate(new Date());
message.setText("Hi Emad" + (char)(10) + "How are you? This is a test mail send by java program"+new Date());
transport = session.getTransport("smtp");
transport.send(message);
System.out.println("Your Mail Send Successfully");
}
catch (MessagingException e) {System.out.println("1)" + e.toString());}
catch (UnsupportedEncodingException e) {System.out.println("2)" + e.toString());}
}
});
this.setSize(600,600);
this.setVisible(true);
}
public static void main(String args[])
{
new Mail();
}
}
//java mail depends on http://java.sun.com/products/javabeans/glasgow/jaf.html
//Set your CLASSPATH to include the "mail.jar" file obtained from
// the download, as well as the current directory.
//
// Assuming you unzipped javamail-1_2.zip in c:download the
// following would work:
//
// set CLASSPATH=%CLASSPATH%;c:downloadjavamail-1.2mail.jar;.
//
// Also include the "activation.jar" file that you obtained from
// downloading the JavaBeans Activation Framework, in your CLASSPATH.
//
// set CLASSPATH=%CLASSPATH%;c:downloadactivationactivation.jar
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mail extends JFrame
{
JLabel jlSendMail = new JLabel("Send Mail");
public Mail()
{
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlSendMail);
jlSendMail.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
try{
String host = "smtp.21cn.com";//"Mail Server in your Company";
String from = "aaaa@21cn.com";//"From Email";
String to = "bbbb@21cn.com";//"To Email";
Properties props = new Properties();
Session session;
//Store store;
Transport transport;
props.put("mail.smtp.host", host);
session = Session.getInstance(props, null);
//session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from,"Ahmad"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to,"Ahmadwa"));
message.setSubject("First");
//message.setSentDate(new Date());
message.setText("Hi Emad" + (char)(10) + "How are you? This is a test mail send by java program"+new Date());
transport = session.getTransport("smtp");
transport.send(message);
System.out.println("Your Mail Send Successfully");
}
catch (MessagingException e) {System.out.println("1)" + e.toString());}
catch (UnsupportedEncodingException e) {System.out.println("2)" + e.toString());}
}
});
this.setSize(600,600);
this.setVisible(true);
}
public static void main(String args[])
{
new Mail();
}
}
|
给JLABEL加事件监听啊,然后用javamail,应该很好实现的
|
new JLable("Hello").addMouseListener(
new MouseAdapter(){
public void mouseEntered(MouseEvent me){
//在这里加入产生下划线的代码。
}
public void mouseClicked(MouseEvent me){
//调用javamail
}
});
//大概就是这样的
new MouseAdapter(){
public void mouseEntered(MouseEvent me){
//在这里加入产生下划线的代码。
}
public void mouseClicked(MouseEvent me){
//调用javamail
}
});
//大概就是这样的
|
his mail
不知道是不是你的意思
不知道是不是你的意思