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

📄 sender.java

📁 没有什么难的
💻 JAVA
字号:
package UI;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Properties;
import java.sql.*;

import DB.*;

import javax.swing.*;
import javax.swing.event.*;

public class Sender extends JPanel implements ActionListener
{
	JLabel lSmtp = new JLabel("smtp");
	JLabel lUser = new JLabel("登录名");
	JLabel lPwd = new JLabel("密码");
	JLabel lEmail = new JLabel("邮箱");
	JTextField tSmtp;
	JTextField tUser;
	JPasswordField tPwd;
	JTextField tEmail;
	JButton btModify = new JButton("修改");
	JButton btSave = new JButton("保存");
	JButton btLoad = new JButton("载入");
	String smtp = null;
	String user = null;
	String pwd = null;
	String email = null;
	
	Properties pro = new Properties();
	FileInputStream read;
	
	DB db;
	ResultSet rs;
	
	public Info info = new Info();
	public Sender(Info info)
	{
		this.info = info;
		db = new DB();
		
		try
		{
			//read = new FileInputStream(".\\SendMail\\setting.ini");
			read = new FileInputStream("MailSetting.ini");
			pro.load(read);
			smtp = pro.getProperty("smtp");
			user = pro.getProperty("user");
			pwd = pro.getProperty("pwd");
			email = pro.getProperty("email");
			info.setSmtp(smtp);
			info.setUser(user);
			info.setPwd(pwd);
			info.setEmail(email);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		tSmtp = new JTextField(smtp);
		tUser = new JTextField(user);
		tPwd = new JPasswordField(pwd);
		tEmail = new JTextField(email);
		
		this.setLayout(null);
		this.setSize(800,600);
		
		lSmtp.setBounds(50,50,60,35);
		lUser.setBounds(50,150,60,35);
		lPwd.setBounds(50,250,60,35);
		lEmail.setBounds(50,350,60,35);
		
		tSmtp.setBounds(100,50,200,35);
		tUser.setBounds(100,150,200,35);
		tPwd.setBounds(100,250,200,35);
		tEmail.setBounds(100,350,200,35);
		
		btModify.setBounds(90,450,80,35);
		btModify.addActionListener(this);
		btSave.setBounds(210,450,80,35);
		btSave.addActionListener(this);
		btLoad.setBounds(330,450,80,35);
		btLoad.addActionListener(this);
		
		this.add(lSmtp); this.add(lUser); this.add(lPwd);this.add(lEmail);
		this.add(tSmtp);this.add(tUser);this.add(tPwd);this.add(tEmail);
		this.add(btModify);this.add(btSave);this.add(btLoad);

		

	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == btModify)
		{
			tSmtp.setText("");
			tUser.setText("");
			tPwd.setText("");
			tEmail.setText("");
		}
		if(e.getSource() == btSave)
		{
			smtp = tSmtp.getText();
			user = tUser.getText();
			pwd = new String(tPwd.getPassword());
			email = tEmail.getText();
			info.setSmtp(smtp);
			info.setUser(user);
			info.setPwd(pwd);
			info.setEmail(email);
			
			String sql = "update info set smtp='"+smtp+"',username='"+user+"'," +
					"pwd='"+pwd+"',email='"+email+"'where id='001'";
			db.update(sql);			
		}
		if(e.getSource() == btLoad)
		{
			String sqlLoad = "select * from info where id ='001'";
			rs = db.search(sqlLoad);
			try {
				while(rs.next())
				{
					smtp = rs.getString("smtp");
					user = rs.getString("username");
					pwd = rs.getString("pwd");
					email = rs.getString("email");
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			tSmtp.setText(smtp);
			tUser.setText(user);
			tPwd.setText(pwd);
			tEmail.setText(email);
			info.setSmtp(smtp);
			info.setUser(user);
			info.setPwd(pwd);
			info.setEmail(email);
			
		}
	}
	public static void main(String args[])
	{
		JFrame f = new JFrame();
		f.add(new Sender(new Info()));
		f.setSize(800,600);
		f.setVisible(true);
	}
}

⌨️ 快捷键说明

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