JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JAVA技术--APPLET  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
这是个用APPLET发送E-MAIL的源代码
作者:未知     文章来源:www.jspcn.net
访问次数:1290次     加入时间:2005年01月19日
都要用到JBuilder里的一个组件,
你可以去JBuilder目录下拷,
或自己用JDK的组件改一下

NO 1:这个程序调用Foxmail发送信件

/*这个程序要用到Jbuilder的几个类*/


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import java.net.*;


public class EmailApplet extends Applet{
Button button;
TextField textField;

public EmailApplet(){}
public void init(){
try{
jbInit();}
catch(Exception e){
e.printStackTrace();}
}//end of init()

public void jbInit()throws Exception{
setLayout(new BorderLayout());
button=new Button("sendMail");
textField=new TextField();
add("North",textField);
add("South",button);
}//end of jbInit()

public boolean action(Event e,Object arg){
if(arg.equals("sendMail")){
try{
/*注意哦,这里是主要代码!!*/
String mailto=textField.getText();
URL url=new URL(mailto);
AppletContext ac=this.getAppletContext();
ac.showDocument(url);}
catch(Exception e2){
System.out.println(e2.toString());}
}//end of if
else{
return super.action(e,arg);}
return true;
}//end of action()


}//end of EmailApplet



NO 2:这个程序直接发送信件:

import borland.jbcl.layout.*;
import borland.jdbl.*;
import java.awt.*;
import java.applet.Applet;
import java.util.StringTokenizer;
import java.net.Socket;
import java.io.PrintStream;
import java.lang.Exception;
import java.awt.event.ActionEvent;


public class MailApplet extends Applet{
boolean isStandalone=false;
PaneLayout panelLayout1=new PaneLayout();
panel panel1=new Panel();
Label label1=new Label();
XYLayout xYLayout1=new XYLayout();
Label Label2=new Label();
TextField textField1=new TextField();
TextField textField2=new TextField();
Label lable3=new Label();
TextArea textArea1=new TextArea();
Button button1=new Button();
Button button2=new Button();
private int SMTP_PORT=25;
Frame frame=new Frame();
Color bgcolor=null;
String send="";
String get="";

public MailApplet(){}

public void init(){
try{
int c1=Integer.parseInt(getParameter("color1"));
int c2=Integer.parseInt(getParameter("color2"));
int c3=Integer.parseInt(getParameter("color3"));
bgcolor=new Color(c1,c2,c3);
SMTP_PORT=Integer.parseInt(getParameter("port"));
send=getParameter("send");
get=getParameter("get");
jbInit();}
catch(Exception e){
e.printStackTrace();}
}//end of init()

/*Component initialization*/
private void jbInit()throws Exception{
this.setSize(new Dimension(332,280));
panel1.setBackground(bgcolor);
label1.setAlignment(2);
label1.setText("收信人地址:");
label2.setAlignment(2);
label2.setText("寄信人地址:");
label3.setAlignment(2);
label3.setText("内容:");
button1.setLabel("发 送");
button1.addActionListener(new MailApplet_button1_actionAdapter(this));
button2.setLabel("清 除");
button2.addActionListener(new MailApplet_button2_actionAdapter(this));
panel1.setLayout(xYLayout);

this.setLayout(panelLayout1);
thsi.add(panel1,new PaneConstraints("panel1","panel1",PaneConstraints.ROOT,1.0f));

panel1.add(label1,new XYConstraints(10,5,80,20));
panel1.add(label2,new XYConstraints(10,30,80,20));
panel1.add(textField1,new XYConstraints(95,5,200,20));
panel1.add(textField2,new XYConstraints(95,30,200,20));
panel1.add(label3,new XYConstraints(10,60,80,20));
panel1.add(textArea1,new XYConstraints(10,80,300,150));
panel1.add(button1,new XYConstraints(50,240,80,25));
panel1.add(button2,new XYConstraints(160,240,80,25));

textField1.setText(get);
textField2.setText(send);
}//end of jbInit()


public String getAppletInfo(){
return "Applet Information";}


public String[][] getParameteInfo(){
return null;}


void sendMail(){
String sender=textField2.getText();
String geter=textField1.getText();
String memo=textArea1.getText();
StringTokenizer st=new StringTokenizer(sender,"@");
int count=st.countTokens();
if(count!=2){
MessageDialog mdlg=new MessageDialog(frame,"邮件地址错误","你的发信人地址错误,请确认后重新发送!!",1);
mdlg.show();
textField2.selectAll();
return;}
String senderName=st.nextToken();
String senderHost=st.nextToken();
st=new StringTokenizer(geter,"@");
count=st.countTokens();
if(count!=2){
MessageDialog mdlg=new MessageDialog(frame,"邮件地址错误","你的收信人地址错误,请确认后重新发送!!",1);
mdlg.show();
textField1.selectAll();
return;}
String geterName=st.nextToken();
String geterHost=st.nextToken();
try{
Socket s=new Socket(geterHost,SMTP_PORT);
PrintStream out=new PrintStream(s.getOutputStream());
out.println("HELLO:"+senderHost);
/*邮件服务器不认证读者所输SMTP是否正确*/
out.println("MAIL FORM:"+senderName);
out.println("RCPT TO:"+geterName);
out.println("DATA");
out.println(memo);
out.println(". QUIT");
MessageDialog mdlg=new MessageDialog(frame,"邮件地址正确","恭喜,您的邮件已经成功发送",1);
mdlg.show();}
catch(Exception e){
System.out.println(e.toString());
MessageDialog mdlg=new MessageDialog(frame,"邮件发送失败",e.toString(),1);//"邮件发送出错,请确认合重新发送!",1);
mdlg.show();
return;}
}//end of sendMail()


void button1_actionPerformed(ActionEvent e){
sendMail();
textArea1.setText("");}


void button2_actionPerformed(ActionEvent e){
textField1.setText("");
textFIeld2.setText("");
textArea1.setText("");}

}//end of MailApplet




class MailApplet_button1_actionAdapter implements java.awt.event.ActionListener{
MailApplet adaptee;
MailApplet_button1_actionAdapter(MailApplet adaptee){
this.adaptee=adaptee;}

public void actionPerformed(ActionEvent e){
adaptee.button1_actionPerformed(e);}
}//end of this




class MailApplet_button2_actionAdapter implements java.awt.event.ActionListener{
MailApplet adaptee;
MailApplet_button2_actionAdapter(MailApplet adaptee){
this.adaptee=adaptee;}
public void actionPerformed(ActionEvent e){
adaptee.button2_actionPerformed(e);}
}//end of this




 
JSP虚拟主机 | JSP空间 | JSP主机 | JSP双线虚拟主机 | JAVA空间 | JAVA虚拟主机 | 虚拟服务器 | JSP 虚拟服务器 | VPS
Virtual Private Server | JAVA虚拟服务器 | VM服务器 | VHOST | 虚拟操作系统 | JSP论坛 | JAVA论坛 | JSP站点论坛
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号