⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 normalpanel.java

📁 基于java的电子邮件群发系统,基于java的电子邮件群发系统
💻 JAVA
字号:
package com.cwq.batchmail.gui;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileFilter;

import com.cwq.batchmail.DetailPacket;
import com.cwq.batchmail.htmltoolbar.HtmlToolBar;
import com.cwq.batchmail.util.LoadEmails;
import com.cwq.batchmail.util.LoadProxies;

abstract class NormalPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTextField jtf_mails = null;
	private JTextField jtf_proxy = null;
	private JButton jb_showdlg = null;
	private JButton jb_showdlg1 = null;
	private JComboBox jcb_threadcount = null;
	private JButton jb_proxies_clean = null;
	private JButton jb_email_clean = null;
	private JCheckBox jcb_useproxy = null;
	private JButton jb_next = null;
	
	abstract void alert(final String msg);
	abstract void log(final String log);
	abstract void onNextStep(final boolean isContinue);

	public NormalPanel() {
		// TODO Auto-generated constructor stub
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setLayout(null);
		this.setBackground(Color.white);
		
		JLabel jLabel1 = new JLabel();
		jLabel1.setBounds(new Rectangle(30, 73, 137, 20));
		jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabel1.setText("EMail地址文件:");
		JLabel jLabel31 = new JLabel();
		jLabel31.setBounds(new Rectangle(174, 94, 246, 23));
		jLabel31.setText("每行一个EMail地址");
		jLabel31.setFont(HtmlToolBar.font1);
		this.add(jLabel1, null);
		this.add(jLabel31, null);
		this.add(getJtf_mails(), null);
		this.add(getJb_showdlg(), null);
		
		JLabel jLabel9 = new JLabel();
		jLabel9.setBounds(new Rectangle(30, 117, 137, 20));
		jLabel9.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabel9.setText("使用代理:");
		this.add(jLabel9, null);
		this.add(getJcb_useproxy(), null);
		
		JLabel jLabel2 = new JLabel();
		jLabel2.setBounds(new Rectangle(30, 144, 137, 20));
		jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabel2.setText("代理服务器文件:");
		jLabel2.setFont(HtmlToolBar.font1);
		JLabel jLabel4 = new JLabel();
		jLabel4.setBounds(new Rectangle(174, 165, 375, 25));
		jLabel4.setText("仅支持匿名的SOCK4或SOCK5代理,格式为: 服务器地址 端口");
		jLabel4.setFont(HtmlToolBar.font1);
		this.add(jLabel2, null);
		this.add(jLabel4, null);
		this.add(getJtf_proxy(), null);
		this.add(getJb_showdlg1(), null);
		
		JLabel jLabel8 = new JLabel();
		jLabel8.setBounds(new Rectangle(30, 201, 137, 20));
		jLabel8.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabel8.setText("最多并发线程数:");
		this.add(jLabel8, null);
		this.add(getJcb_threadcount(), null);
		
		JLabel jLabel5 = new JLabel();
		jLabel5.setBounds(new Rectangle(440, 200, 107, 64));
		jLabel5.setText("");
		try {
			jLabel5.setIcon(new ImageIcon(new URL(DetailPacket.imagesPath.concat("bg.gif"))));
		} catch(Exception ex) {}
		
		this.add(getJb_proxies_clean(), null);
		this.add(getJb_email_clean(), null);
		
		this.add(getJb_next(), null);
		
		this.add(jLabel5, null);
		
	}
		
		private JTextField getJtf_mails() {
			if (jtf_mails == null) {
				jtf_mails = new JTextField();
				jtf_mails.setBounds(new Rectangle(174, 73, 210, 21));
				//jtf_mails.setPreferredSize(jtf_mails.getSize());
				jtf_mails.setEditable(false);
			}
			return jtf_mails;
		}
		
		private JCheckBox getJcb_useproxy() {
			if(jcb_useproxy == null) {
				jcb_useproxy = new JCheckBox();
				jcb_useproxy.setBounds(new Rectangle(174, 117, 32, 20));
				jcb_useproxy.setSelected(DetailPacket.useProxy);
				jcb_useproxy.setBackground(Color.white);
				jcb_useproxy.setBorder(null);
				jcb_useproxy.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(MouseEvent e) {
						jcb_useproxy_State();
					}
				});
				jcb_useproxy_State();
			}
			return jcb_useproxy;
		}
		
		private void jcb_useproxy_State() {
			if(!getJcb_useproxy().isSelected()) {
				getJtf_proxy().setEnabled(false);
				getJb_showdlg1().setEnabled(false);
			}
			else {
				getJtf_proxy().setEnabled(true);
				getJb_showdlg1().setEnabled(true);
			}
		}
		
		private JTextField getJtf_proxy() {
			if (jtf_proxy == null) {
				jtf_proxy = new JTextField();
				jtf_proxy.setBounds(new Rectangle(174, 144, 210, 21));
				jtf_proxy.setEditable(false);
			}
			return jtf_proxy;
		}
		
		private JButton getJb_showdlg() {
			if (jb_showdlg == null) {
				jb_showdlg = new JButton();
				jb_showdlg.setBounds(new Rectangle(399, 73, 66, 21));
				jb_showdlg.setText("浏览");
				
				jb_showdlg.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(java.awt.event.MouseEvent e) {
						fileChooser(getJtf_mails(), "请选择EMail存放的文件 (*.txt | *.TXT)");
					}
				}); 
			}
			return jb_showdlg;
		}
		
		private JButton getJb_showdlg1() {
			if (jb_showdlg1 == null) {
				jb_showdlg1 = new JButton();
				jb_showdlg1.setBounds(new Rectangle(399, 144, 66, 21));
				jb_showdlg1.setText("浏览");
				
				jb_showdlg1.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(java.awt.event.MouseEvent e) {
						if(jb_showdlg1.isEnabled())
							fileChooser(getJtf_proxy(), "请选择代理服务器存放的文件 (*.txt | *.TXT)");
					}
				}); 
			}
			return jb_showdlg1;
		}
		
		private JComboBox getJcb_threadcount() {
			if (jcb_threadcount == null) {
				jcb_threadcount = new JComboBox();
				jcb_threadcount.setBounds(new Rectangle(174, 201, 69, 20));
				int item = 0;
				int selectedItem = 0;
				for (int c=10; c<=200; c = c * 2) {
					jcb_threadcount.addItem("" + c);
					if(c == DetailPacket.threadCount) selectedItem = item;
					item ++;
						
				}
				jcb_threadcount.setSelectedIndex(selectedItem);
			}
			return jcb_threadcount;
		}
		
		private JButton getJb_email_clean() {
			if (jb_email_clean == null) {
				jb_email_clean = new JButton();
				jb_email_clean.setBounds(new Rectangle(170, 288, 137, 26));
				jb_email_clean.setText("去掉重复的EMAIL");
				
				jb_email_clean.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(java.awt.event.MouseEvent e) {
						if(getJtf_mails().getText().trim().length() == 0) {
							return ;
						}
						File emails = new File(getJtf_mails().getText());
						if(!emails.exists() || !emails.isFile()) {
							alert("请选择EMAIL存放的文件,再进行清理。");
							return ;
						}
						try {
							LoadEmails lm = new LoadEmails();
							int count = lm.clean(emails).size();
							int total = lm.getTotalEmailsCount();
							String tips = "原有 " + total + " 个EMAIL,去掉重复出现的 " + (total - count) + " 个EMAIL。";
							alert(tips);
							log(tips);
							//getJta_log().append("\r\n".concat(tips));
						} catch(IOException ex) {
							alert("出错:" + ex.getMessage());
							return ;
						}
					}
				}); 
			}
			return jb_email_clean;
		}
		
		private JButton getJb_proxies_clean() {
			if (jb_proxies_clean == null) {
				jb_proxies_clean = new JButton();
				jb_proxies_clean.setBounds(new Rectangle(320, 288, 131, 26));
				jb_proxies_clean.setText("去掉重复的代理");
				
				jb_proxies_clean.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(java.awt.event.MouseEvent e) {
						if(getJtf_proxy().getText().trim().length() == 0) {
							return ;
						}
						File proxies = new File(getJtf_proxy().getText());
						if(!proxies.exists() || !proxies.isFile()) {
							alert("请选择代理服务器存放的文件,再进行清理。");
							return ;
						}
						try {
							LoadProxies lp = new LoadProxies();
							int count = lp.clean(proxies).size();
							int total = lp.getTotalProxiesCount();
							String tips = "原有 " + total + " 个代理,去掉重复出现的 " + (total - count) + " 个代理。";
							alert(tips);
							log(tips);
							//getJta_log().append("\r\n".concat(tips));
						} catch(IOException ex) {
							alert("出错:" + ex.getMessage());
							return ;
						}
					}
				}); 
			}
			return jb_proxies_clean;
		}
		
		private JButton getJb_next() {
			if (jb_next == null) {
				jb_next = new JButton();
				jb_next.setBounds(new Rectangle(464, 288, 91, 26));
				jb_next.setText("下一步");
				jb_next.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseClicked(java.awt.event.MouseEvent e) {
						if(getJtf_mails().getText().trim().length() == 0
								|| (getJtf_proxy().getText().trim().length() == 0 && getJcb_useproxy().isSelected())
								) {
							alert("请先选择相应的配置文件");
							onNextStep(false);
							return ;
						}
						DetailPacket.emailFile = getJtf_mails().getText().trim();
						DetailPacket.proxyFile = getJtf_proxy().getText().trim();
						DetailPacket.useProxy = getJcb_useproxy().isSelected();
						DetailPacket.threadCount = Integer.parseInt(getJcb_threadcount().getSelectedItem().toString());
						onNextStep(true);
					}
				});
			}
			return jb_next;
		}
		
		void fileChooser(final JTextField jtf, final String desc) {
			JFileChooser chooser = new JFileChooser();
		    FileFilter filter = new FileFilter() {
		    	public boolean accept(File f) {
		    		return f.isDirectory() || (f.isFile() && (
		    				f.getName().endsWith(".txt")
		    				|| f.getName().endsWith(".TXT")
		    				));
		    	}
		    	public String getDescription() {
		    		return desc;
		    	}
		    };
		    chooser.setFileFilter(filter);
		    int returnVal = chooser.showOpenDialog(this);
		    if(returnVal == JFileChooser.APPROVE_OPTION) {
		    	jtf.setText(chooser.getSelectedFile().getPath());
		    }
		}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -