package puturl; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.io.*; /** *
Title:
*Description:
*Copyright: Copyright (c) 2005
*Company:
* @author not attributable * @version 1.0 */ public class Applet1 extends Applet { private boolean isStandalone = false; Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); Label label4 = new Label(); TextField textFieldFrom = new TextField(); TextField textFieldTo = new TextField(); TextField textFieldsbj = new TextField(); TextField textFieldmsg = new TextField(); Button buttonSend = new Button(); //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 { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { label1.setText("From"); label1.setBounds(new Rectangle(25, 49, 28, 15)); this.setLayout(null); label2.setText("to"); label2.setBounds(new Rectangle(19, 81, 52, 15)); label3.setLocale(java.util.Locale.getDefault()); label3.setText("Sub"); label3.setBounds(new Rectangle(21, 113, 48, 20)); label4.setText("msg"); label4.setBounds(new Rectangle(22, 149, 37, 23)); textFieldFrom.setText("mito@sccs.chukyo-u.ac.jp"); textFieldFrom.setBounds(new Rectangle(85, 49, 158, 17)); textFieldTo.setText("yt7m-itu@asahi-net.or.jp"); textFieldTo.setBounds(new Rectangle(85, 76, 166, 22)); textFieldsbj.setText("test"); textFieldsbj.setBounds(new Rectangle(77, 112, 114, 22)); textFieldmsg.setText("Hello"); textFieldmsg.setBounds(new Rectangle(81, 151, 202, 23)); buttonSend.setLabel("M"); buttonSend.setBounds(new Rectangle(104, 218, 86, 28)); buttonSend.addActionListener(new Applet1_buttonSend_actionAdapter(this)); this.add(label4, null); this.add(textFieldmsg, null); this.add(label3, null); this.add(textFieldsbj, null); this.add(label1, null); this.add(label2, null); this.add(textFieldTo, null); this.add(textFieldFrom, null); this.add(buttonSend, null); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } void buttonSend_actionPerformed(ActionEvent e) { try{ URL url=new URL("http://150.42.41.129/cgi-bin/tool/sendmail.cgi"); URLConnection uc = url.openConnection(); uc.setDoOutput(true); uc.setUseCaches(false); System.out.println("connected?"); PrintWriter pw = new PrintWriter(uc.getOutputStream()); String data="from="+textFieldFrom.getText()+"&to="+textFieldTo.getText() +"&title="+textFieldsbj.getText()+"&msg="+textFieldmsg.getText(); String postdata=data; System.out.println("send:"+postdata); pw.print(postdata); pw.flush(); pw.close(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); String line=""; String answer= ""; while((line = br.readLine()) != null){ answer += line + "_n"; //System.out.println(answer); } System.out.println(answer); br.close(); } catch(Exception ex){ ex.printStackTrace(); } } } class Applet1_buttonSend_actionAdapter implements java.awt.event.ActionListener { Applet1 adaptee; Applet1_buttonSend_actionAdapter(Applet1 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.buttonSend_actionPerformed(e); } }