Here is a simple Email Applet which will cause the
user's email client to bring up a filled in email message when clicked which you could adapt to your project and send simple email messages to others.
You could easily adapt this to your particular situation:
/* EmailApplet.java
* @author: Charles Bell
* @version: June 17, 2002
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class EmailApplet extends Applet implements ActionListener{
private TextField fromField;
private TextField toField;
private TextField subjectField;
private TextArea bodyArea;
public void init(){
Panel top = new Panel();
top.setLayout(new GridLayout(2,2));
Panel middle = new Panel();
Panel bottom = new Panel();
toField = new TextField(20);
subjectField = new TextField(20);
bodyArea = new TextArea(4,50);
Button sendButton = new Button("Send");
sendButton.addActionListener(this);
top.add(new Label("To:"));
top.add(toField);
top.add(new Label("Subject:"));
top.add(subjectField);
middle.add(bodyArea);
bottom.add(sendButton);
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
add(middle, BorderLayout.CENTER);
add(bottom, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent ae){
if (ae.getActionCommand().compareTo("Send") == 0){
sendIt();
}
}
public void sendIt(){
String to = toField.getText();
String subject = subjectField.getText();
String body = bodyArea.getText();
String urlString = "mailto:"+to +"?"
+"&Subject=" + subject
+"&Body=" + body;
try{
URL mailUrl = new URL(urlString);
AppletContext context = getAppletContext();
context.showDocument(mailUrl);
}catch(MalformedURLException murle){
System.err.println("MalformedURLException: " + murle.getMessage());
}
}
}
<html>
<head>
<title>EmailApplet</title>
</head>
<body>
??? <center><applet code="EmailApplet.class" width="400" height="200"></applet></center>
</body>
</html>
This applet is live now at:
http://www.quantumhyperspace.com/EmailApplet/EmailApplet.html
you can try it out and send someone or yourself a message.