📄 frame1.java~22~
字号:
package sendmail;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.mail.*;import javax.mail.internet.*;import java.util.*;import com.borland.jbcl.layout.*;/** * <p>Title: no</p> * <p>Description: This a Java builder program</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: home</p> * @author liujun * @version 1.0 */public class Frame1 extends JFrame { private JPanel contentPane; private XYLayout xYLayout1 = new XYLayout(); private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); private JLabel jLabel3 = new JLabel(); private JLabel jLabel4 = new JLabel(); private JTextField jTextField1 = new JTextField(); private JTextField jTextField2 = new JTextField(); private JTextField jTextField3 = new JTextField(); private JTextField jTextField4 = new JTextField(); private JButton jButton1 = new JButton(); private JScrollPane jScrollPane1 = new JScrollPane(); private JTextArea jTextArea1 = new JTextArea(); //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); jLabel1.setText("收信人地址:"); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("发送邮件"); jLabel2.setText("抄 送:"); jLabel3.setText("暗 抄:"); jLabel4.setText("主 题:"); jTextField1.setText("lori@163.com"); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText("新邮件"); jButton1.setText("发 信"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jTextArea1.setText(" "); contentPane.add(jLabel1, new XYConstraints(13, 11, 78, 24)); contentPane.add(jLabel2, new XYConstraints(13, 45, 78, 24)); contentPane.add(jLabel3, new XYConstraints(13, 83, 78, 24)); contentPane.add(jLabel4, new XYConstraints(13, 119, 78, 24)); contentPane.add(jTextField2, new XYConstraints(85, 45, 186, 23)); contentPane.add(jTextField1, new XYConstraints(85, 11, 186, 23)); contentPane.add(jTextField3, new XYConstraints(85, 83, 186, 23)); contentPane.add(jTextField4, new XYConstraints(85, 119, 186, 23)); contentPane.add(jButton1, new XYConstraints(305, 21, 82, 22)); contentPane.add(jScrollPane1, new XYConstraints(17, 155, 371, 137)); jScrollPane1.getViewport().add(jTextArea1, null); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) { try{ Properties props = new Properties(); props.put("mail.host","smtp.371.net"); Session mailConnection = Session.getInstance(props,null); Message msg = new MimeMessage(mailConnection);// Address sendman=new InternetAddress("lorime@163.com"); Address sendman=new InternetAddress("lunhui@371.net"); Address recieveman=new InternetAddress(jTextField1.getText()); msg.setContent(jTextArea1.getText(),"text/plain"); msg.setFrom(sendman); msg.setRecipient(Message.RecipientType.TO,recieveman); msg.setSubject(jTextField4.getText()); Transport.send(msg); } catch (Exception ex){ ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -