6个回答
展开全部
package email;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Closeable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Test extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame jf = new JFrame();
JPanel jp = new JPanel();
JButton jb;
JTextArea jta;
JTextField jtf1, jtf2, jtf3;
JLabel jl1, jl2, jl3, jl4;
JPasswordField jpwd;
public Test() {
jl1 = new JLabel("发信人邮箱:");
jtf1 = new JTextField(20);
jl4 = new JLabel("发信人密码:");
jpwd = new JPasswordField(20);
jl2 = new JLabel("收信人邮箱:");
jtf2 = new JTextField(20);
jl3 = new JLabel("邮件内容");
jta = new JTextArea(14, 28);
jb = new JButton("发送");
jp.add(jl1);
jp.add(jtf1);
jp.add(jl4);
jp.add(jpwd);
jp.add(jl2);
jp.add(jtf2);
jp.add(jl3);
jp.add(jta);
jp.add(jb);
jf.add(jp);
jb.addActionListener(this);
jf.setTitle("163邮箱简易发送软件");
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setBounds(0, 0, 340, 450); //
jf.setResizable(false); // 居中显示
jf.setLocationRelativeTo(null); // 窗体可见
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb) {
String hairemail = jtf1.getText();
String closeemail = jtf2.getText();
String password =jpwd.getText();
String content = jta.getText();
if (hairemail.equals("")|| hairemail==null) {
JOptionPane.showMessageDialog(null, "发件人邮箱不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (closeemail.equals("")||closeemail==null ) {
JOptionPane.showMessageDialog(null, "发件人密码不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (password.equals("")||password==null) {
JOptionPane.showMessageDialog(null, "收件人邮箱不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (content.equals("")||content==null) {
JOptionPane.showMessageDialog(null, "邮件内容不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if ( isEmail(hairemail) == false) {
JOptionPane.showMessageDialog(null, "发信人邮箱格式不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if ( isEmail(closeemail) == false) {
JOptionPane.showMessageDialog(null, "收信人邮箱格式不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if(!"163.com".equals(isCheck(hairemail, "@",1))){
JOptionPane.showMessageDialog(null, "发件人邮箱必须为163邮箱", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
Email email = new Email();
String strreturn=email.simpleEmail(closeemail, content, hairemail, password);
if("success".equals(strreturn)){
JOptionPane.showMessageDialog(null, "邮件发送成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if("err".equals(strreturn)){
JOptionPane.showMessageDialog(null, "发信人邮箱或密码不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if("err1".equals(strreturn)){
JOptionPane.showMessageDialog(null, "未知错误请联系管理员", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
public String isCheck(String email,String str,int i ){
String[] newString=email.split(str);
return newString[i];
}
public static boolean isEmail(String str) {
String regex ="^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
return match(regex, str);
}
private static boolean match(String regex, String str) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}
public static void main(String[] args) {
new Test();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Closeable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Test extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame jf = new JFrame();
JPanel jp = new JPanel();
JButton jb;
JTextArea jta;
JTextField jtf1, jtf2, jtf3;
JLabel jl1, jl2, jl3, jl4;
JPasswordField jpwd;
public Test() {
jl1 = new JLabel("发信人邮箱:");
jtf1 = new JTextField(20);
jl4 = new JLabel("发信人密码:");
jpwd = new JPasswordField(20);
jl2 = new JLabel("收信人邮箱:");
jtf2 = new JTextField(20);
jl3 = new JLabel("邮件内容");
jta = new JTextArea(14, 28);
jb = new JButton("发送");
jp.add(jl1);
jp.add(jtf1);
jp.add(jl4);
jp.add(jpwd);
jp.add(jl2);
jp.add(jtf2);
jp.add(jl3);
jp.add(jta);
jp.add(jb);
jf.add(jp);
jb.addActionListener(this);
jf.setTitle("163邮箱简易发送软件");
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setBounds(0, 0, 340, 450); //
jf.setResizable(false); // 居中显示
jf.setLocationRelativeTo(null); // 窗体可见
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb) {
String hairemail = jtf1.getText();
String closeemail = jtf2.getText();
String password =jpwd.getText();
String content = jta.getText();
if (hairemail.equals("")|| hairemail==null) {
JOptionPane.showMessageDialog(null, "发件人邮箱不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (closeemail.equals("")||closeemail==null ) {
JOptionPane.showMessageDialog(null, "发件人密码不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (password.equals("")||password==null) {
JOptionPane.showMessageDialog(null, "收件人邮箱不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (content.equals("")||content==null) {
JOptionPane.showMessageDialog(null, "邮件内容不能为空", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if ( isEmail(hairemail) == false) {
JOptionPane.showMessageDialog(null, "发信人邮箱格式不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if ( isEmail(closeemail) == false) {
JOptionPane.showMessageDialog(null, "收信人邮箱格式不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if(!"163.com".equals(isCheck(hairemail, "@",1))){
JOptionPane.showMessageDialog(null, "发件人邮箱必须为163邮箱", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
Email email = new Email();
String strreturn=email.simpleEmail(closeemail, content, hairemail, password);
if("success".equals(strreturn)){
JOptionPane.showMessageDialog(null, "邮件发送成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if("err".equals(strreturn)){
JOptionPane.showMessageDialog(null, "发信人邮箱或密码不正确", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if("err1".equals(strreturn)){
JOptionPane.showMessageDialog(null, "未知错误请联系管理员", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
public String isCheck(String email,String str,int i ){
String[] newString=email.split(str);
return newString[i];
}
public static boolean isEmail(String str) {
String regex ="^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
return match(regex, str);
}
private static boolean match(String regex, String str) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}
public static void main(String[] args) {
new Test();
}
}
展开全部
JFrame是顶层容器,不能被包含。不能在一个JFrame容器中嵌套另一个JFrame容器。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-08-21
展开全部
2个jframe? 直接调用另一个 frame的创建就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在一个Jframe里添加第二个JFrame
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询