?? sendform.java
字號(hào):
/* * 發(fā)送郵件 */package MobileEmail;import javax.microedition.lcdui.*;import java.io.IOException;/** * * @author Administrator */public class SendForm extends Form implements CommandListener,Runnable{ private EMailMidlet midlet; private Ticker ticker; private TextField tfRecipients; private TextField tfSubject; private TextField tfContent; private Command cmdSend=new Command("發(fā)送",Command.SCREEN,2); private Command cmdBack=new Command("返回",Command.BACK,1); public SendForm(EMailMidlet midlet){ super("發(fā)送郵件"); this.midlet=midlet; tfRecipients=new TextField("收件人:","",50,TextField.EMAILADDR); tfSubject=new TextField("主題:","",50,TextField.ANY); tfContent=new TextField("內(nèi)容:","",200,TextField.ANY); tfContent.setPreferredSize(super.getWidth(), 120); append(tfRecipients); append(tfSubject); append(tfContent); ticker=new Ticker("編寫郵件!"); setTicker(ticker); addCommand(cmdSend); addCommand(cmdBack); this.setCommandListener(this); } public void clear(){ tfRecipients.setString(""); tfSubject.setString(""); tfContent.setString(""); } public void commandAction(Command c,Displayable d){ if(c==cmdBack){ midlet.BackToMenu(); } else if(c==cmdSend){ String recipients=tfRecipients.getString(); if(recipients.equals("")){ midlet.showAlert("錯(cuò)誤!", "請(qǐng)輸入收件人的地址!"); } else{ ticker.setString("正在發(fā)送郵件,請(qǐng)稍候……"); removeCommand(cmdSend); Thread t=new Thread(this); t.start(); } } } public void run(){ boolean isOK=true; try{ EMailConfig config=EMailConfig.getInstance(); String localhost=System.getProperty("microedition.platform"); SMTPClient smtpClient=new SMTPClient(localhost); smtpClient.open(config.getSMTPServer(),config.getAccounts(),config.getPassword()); String subject=tfSubject.getString(); String content=tfContent.getString(); String recipients=tfRecipients.getString(); smtpClient.send(subject,content,new String[]{recipients}); smtpClient.close(); } catch(IOException emo){ isOK=false; midlet.showAlert("錯(cuò)誤!", emo.toString()); } catch(EMailException ee){ isOK=false; midlet.showAlert("錯(cuò)誤!", ee.toString()); } if(isOK){ ticker.setString("發(fā)送郵件成功!"); } else{ ticker.setString("發(fā)送郵件失?。≌?qǐng)重新發(fā)送!"); } this.addCommand(cmdSend); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -