MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 【讨论】java怎么登陆163邮箱,获取登陆用户的好友

【讨论】java怎么登陆163邮箱,获取登陆用户的好友列表(4)

www.MyException.Cn  网友分享于:2015-08-27  浏览:196次

JPasswordField password = new JPasswordField();
JTextField to = new JTextField(30);
JTextField subject = new JTextField(30);
JTextField multipart = new JTextField(20);
JButton scan = new JButton("浏览");
JTextArea content = new JTextArea();
JButton send = new JButton("发送邮件");
JButton reset = new JButton("重新填写");
Container con = f.getContentPane();

MyAction ma = new MyAction();

public EmailGui() {
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
JLabel lab1 = new JLabel("发件邮箱");
p1.add(lab1, BorderLayout.WEST);
p1.add(from, BorderLayout.CENTER);

JPanel p7 = new JPanel();
p7.setLayout(new BorderLayout());
JLabel lab7 = new JLabel("用户名  ");
p7.add(lab7, BorderLayout.WEST);
p7.add(username, BorderLayout.CENTER);

JPanel p8 = new JPanel();
p8.setLayout(new BorderLayout());
JLabel lab8 = new JLabel("密码");
p8.add(lab8, BorderLayout.WEST);
p8.add(password, BorderLayout.CENTER);

JPanel p9 = new JPanel();
p9.setLayout(new GridLayout(1, 2, 10, 0));
p9.add(p7);
p9.add(p8);

JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
JLabel lab2 = new JLabel("收件邮箱");
p2.add(lab2, BorderLayout.WEST);
p2.add(to, BorderLayout.CENTER);

JPanel p3 = new JPanel();
p3.setLayout(new BorderLayout());
JLabel lab3 = new JLabel("邮件主题");
p3.add(lab3, BorderLayout.WEST);
p3.add(subject, BorderLayout.CENTER);

JPanel p4 = new JPanel();
p4.setLayout(new BorderLayout());
JLabel lab4 = new JLabel("添加附件");
p4.add(lab4, BorderLayout.WEST);
p4.add(scan, BorderLayout.EAST);
p4.add(multipart, BorderLayout.CENTER);

JPanel p5 = new JPanel();
p5.setLayout(new FlowLayout());
p5.add(send);
p5.add(reset);

JPanel p6 = new JPanel();
p6.setLayout(new GridLayout(5, 1));
p6.add(p1);
p6.add(p9);
p6.add(p2);
p6.add(p3);
p6.add(p4);
p6.setBorder(BorderFactory.createTitledBorder("请填写邮件发送参数"));

content.setBorder(BorderFactory.createTitledBorder("邮件正文"));
con.setLayout(new BorderLayout());
con.add(p6, BorderLayout.NORTH);
con.add(content, BorderLayout.CENTER);
con.add(p5, BorderLayout.SOUTH);

scan.addActionListener(ma);
send.addActionListener(ma);
reset.addActionListener(ma);

f.setSize(new Dimension(400, 600));
f.setLocation(200, 100);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public class MyAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
if (e.getSource() == scan) {
JFileChooser chooser = new JFileChooser();
int state = chooser.showDialog(f, "请选择一个需要添加的附件");
if (state == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile()
.getAbsolutePath();
multipart.setText(fileName);
}
} else if (e.getSource() == send) {
Email email = new Email("smtp.qq.com");

email.setNeedAuth(true);
email.setFrom(from.getText().trim());
email.setTo(to.getText().trim());
email.setSubject(subject.getText().trim());
email.setBody(content.getText());
if(!multipart.getText().trim().equals("")){
email.addFileAffix(multipart.getText());
}
email.setNamePass(username.getText().trim(), password.getText()
.trim());

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有