📄 applet1.java
字号:
package untitled2;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.net.*;import java.io.*;import java.lang.*;import java.util.*;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Applet1 extends Applet { boolean isStandalone = false; private int SMTP_PORT=25; String send=""; String get=""; Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); TextField textField1 = new TextField(); TextField textField2 = new TextField(); TextArea textArea1 = new TextArea(); Button button1 = new Button(); JOptionPane jOptionPane1 = new JOptionPane(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { send=getParameter("send"); get=getParameter("get"); jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { label1.setText("收件人地址"); label1.setBounds(new Rectangle(26, 25, 65, 25)); this.setLayout(null); label2.setText("发件人地址"); label2.setBounds(new Rectangle(25, 57, 73, 17)); label3.setText("信件正文:"); label3.setBounds(new Rectangle(25, 87, 80, 24)); textField1.setText("textField1"); textField1.setBounds(new Rectangle(102, 25, 129, 27)); textField2.setText("textField2"); textField2.setBounds(new Rectangle(102, 57, 127, 26)); textArea1.setText("textArea1"); textArea1.setBounds(new Rectangle(31, 116, 247, 96)); button1.setLabel("发送"); button1.setBounds(new Rectangle(117, 237, 89, 27)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); jOptionPane1.setBounds(new Rectangle(346, 23, 165, 74)); this.add(label1, null); this.add(label2, null); this.add(label3, null); this.add(textArea1, null); this.add(jOptionPane1, null); this.add(textField1, null); this.add(textField2, null); this.add(button1, null); jOptionPane1.setVisible(false); textField1.setText(get); textField2.setText(send); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } //Main method public static void main(String[] args) { Applet1 applet = new Applet1(); applet.isStandalone = true; Frame frame; frame = new Frame() { protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public synchronized void setTitle(String title) { super.setTitle(title); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } }; frame.setTitle("Applet Frame"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(400,320); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); } 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) { jOptionPane1.showMessageDialog(null,"您的收件人地址有误,请重新填写!"); textField2.selectAll();; return; } String senderName=st.nextToken(); String senderHost=st.nextToken(); st=new StringTokenizer(geter,"@"); count=st.countTokens(); if(count!=2) { jOptionPane1.showMessageDialog(null,"您的发件人地址有误,请重新填写!"); 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("MAIL FROM:"+senderName); out.println("RCPT TO:"+geterName); out.println("DATA"); out.println(memo); out.println("."); out.println("QUIT"); jOptionPane1.showMessageDialog(null,"您的邮件发送成功!"); } catch(Exception e) { jOptionPane1.showMessageDialog(null,"程序异常错误"+e.toString()); return; } } void button1_actionPerformed(ActionEvent e) { sendMail(); textArea1.setText(""); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -