具体的包、驱动和类的对应位置
目录
com.zzk.bean
com.zzk.dao
com.zzk.frame
com.zzk.panel
com.zzk.tool
com.zzk.bean
ExpressMessage.java
package com.zzk.bean;
public class ExpressMessage {
private int id = 0;
private String sendName = null;
private String sendTelephone = null;
private String sendCompary = null;
private String sendAddress = null;
private String sendPostcode = null;
private String receiveName = null;
private String receiveTelephone = null;
private String receiveCompary = null;
private String receiveAddress = null;
private String receivePostcode = null;
private String ControlPosition = null;
private String expressSize = null;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSendName() {
return sendName;
}
public void setSendName(String sendName) {
this.sendName = sendName;
}
public String getSendTelephone() {
return sendTelephone;
}
public void setSendTelephone(String sendTelephone) {
this.sendTelephone = sendTelephone;
}
public String getSendCompary() {
return sendCompary;
}
public void setSendCompary(String sendCompary) {
this.sendCompary = sendCompary;
}
public String getSendAddress() {
return sendAddress;
}
public void setSendAddress(String sendAddress) {
this.sendAddress = sendAddress;
}
public String getSendPostcode() {
return sendPostcode;
}
public void setSendPostcode(String sendPostcode) {
this.sendPostcode = sendPostcode;
}
public String getReceiveName() {
return receiveName;
}
public void setReceiveName(String receiveName) {
this.receiveName = receiveName;
}
public String getReceiveTelephone() {
return receiveTelephone;
}
public void setReceiveTelephone(String receiveTelephone) {
this.receiveTelephone = receiveTelephone;
}
public String getReceiveCompary() {
return receiveCompary;
}
public void setReceiveCompary(String receiveCompary) {
this.receiveCompary = receiveCompary;
}
public String getReceiveAddress() {
return receiveAddress;
}
public void setReceiveAddress(String receiveAddress) {
this.receiveAddress = receiveAddress;
}
public String getReceivePostcode() {
return receivePostcode;
}
public void setReceivePostcode(String receivePostcode) {
this.receivePostcode = receivePostcode;
}
public String getControlPosition() {
return ControlPosition;
}
public void setControlPosition(String controlPosition) {
ControlPosition = controlPosition;
}
public String getExpressSize() {
return expressSize;
}
public void setExpressSize(String expressSize) {
this.expressSize = expressSize;
}
}
User.java
package com.zzk.bean;
public class User {
private String name = null;
private String pwd = null;
private String okPwd = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getOkPwd() {
return okPwd;
}
public void setOkPwd(String okPwd) {
this.okPwd = okPwd;
}
}
com.zzk.dao
DAO.java
package com.zzk.dao;
/*
* 加载数据库驱动
* 建立数据库连接
*/
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class DAO {
private static DAO dao = new DAO();//声明DAO类的静态实例
public DAO() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载数据库驱动
//System.out.println("数据库驱动加载成功");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "数据库加载失败。\n" + e.getMessage());
}
}
public static Connection getConn() {
try {
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=db_ExpressPrint","use1", "123456");
/*
if(conn != null) {
System.out.println("数据库连接成功");
}
*/
return conn;//返回连接
} catch(Exception e) {
JOptionPane.showMessageDialog(null, "数据库连接失败" + e.getMessage());
return null;
}
}
}
ExpressMessageDao.java
package com.zzk.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;
import com.zzk.bean.ExpressMessage;
public class ExpressMessageDao {
public static void insertExpress(ExpressMessage m) {
if(m.getSendName() == null || m.getSendName().trim().equals("")) {
JOptionPane.showMessageDialog(null, "寄件人信息必须填写");
return ;
}
if(m.getSendTelephone() == null || m.getSendTelephone().trim().equals("")) {
JOptionPane.showMessageDialog(null, "寄件人信息必须填写");
return ;
}
if(m.getSendCompary() == null || m.getSendCompary().trim().equals("")) {
JOptionPane.showMessageDialog(null, "寄件人信息必须填写");
return ;
}
if(m.getSendAddress() == null || m.getSendAddress().trim().contentEquals("||")) {
JOptionPane.showMessageDialog(null, "寄件人信息必须填写");
return ;
}
if(m.getSendPostcode() == null || m.getSendPostcode().trim().equals("")) {
JOptionPane.showMessageDialog(null, "寄件人信息必须填写");
return ;
}
if(m.getReceiveName() == null || m.getReceiveName().trim().equals("")) {
JOptionPane.showMessageDialog(null, "收件人信息必须填写");
return ;
}
if(m.getReceiveTelephone() == null || m.getReceiveTelephone().trim().equals("")) {
JOptionPane.showMessageDialog(null, "收件人信息必须填写");
return ;
}
if(m.getReceiveCompary() == null || m.getReceiveCompary().trim().equals("")) {
JOptionPane.showMessageDialog(null, "收件人信息必须填写");
return ;
}
if(m.getReceiveAddress() == null || m.getReceiveAddress().trim().equals("||")) {
JOptionPane.showMessageDialog(null, "收件人信息必须填写");
return ;
}
if(m.getReceivePostcode() == null || m.getReceivePostcode().trim().equals("")) {
JOptionPane.showMessageDialog(null, "收件人信息必须填写");
return ;
}
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DAO.getConn();
ps = conn.prepareStatement("insert into tb_receiveSendMessage(sendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,receiveTelephone,receiveCompary,receiveAddress,receivePostcode,ControlPosition,expressSize)values(?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1, m.getSendName());
ps.setString(2, m.getSendTelephone());
ps.setString(3, m.getSendCompary());
ps.setString(4, m.getSendAddress());
ps.setString(5, m.getSendPostcode());
ps.setString(6, m.getReceiveName());
ps.setString(7, m.getReceiveTelephone());
ps.setString(8, m.getReceiveCompary());
ps.setString(9, m.getReceiveAddress());
ps.setString(10, m.getReceivePostcode());
ps.setString(11, m.getControlPosition());
ps.setString(12, m.getExpressSize());
int flag = ps.executeUpdate();
if(flag > 0) {
JOptionPane.showMessageDialog(null, "添加成功");
} else {
JOptionPane.showMessageDialog(null, "添加失败");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "添加失败");
e.printStackTrace();
} finally {
try {
if(ps != null) {
ps.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void updateExpress(ExpressMessage m) {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DAO.getConn();
ps = conn.prepareStatement("update tb_receiveSendMessage set sendName=?,sendTelephone=?,sendCompary=?,sendAddress=?,"
+ "sendPostcode=?,receiveName=?,receiveTelephone=?,receiveCompary=?,receiveAddress=?,receivePostcode=?,"
+ "ControlPosition=?,expressSize=? where id = ?");
ps.setString(1, m.getSendName());
ps.setString(2, m.getSendTelephone());
ps.setString(3, m.getSendCompary());
ps.setString(4, m.getSendAddress());
ps.setString(5, m.getSendPostcode());
ps.setString(6, m.getReceiveName());
ps.setString(7, m.getReceiveTelephone());
ps.setString(8, m.getReceiveCompary());
ps.setString(9, m.getReceiveAddress());
ps.setString(10, m.getReceivePostcode());
ps.setString(11, m.getControlPosition());
ps.setString(12, m.getExpressSize());
ps.setInt(13, m.getId());
int flag = ps.executeUpdate();
if(flag > 0) {
JOptionPane.showMessageDialog(null, "修改成功");
} else {
JOptionPane.showMessageDialog(null, "修改失败");
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "修改失败!" + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if(ps != null) {
ps.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static Vector<ExpressMessage> queryExpress() {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DAO.getConn();
ps = conn.prepareStatement("select sendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,receiveTelephone,receiveCompary,receiveAddress,"
+ "receivePostcode,ControlPosition,expressSize fromtb_receiveSendMessage");
ResultSet rs = ps.executeQuery();
Vector<ExpressMessage> v = new Vector<ExpressMessage>();
while (rs.next()) {
ExpressMessage m = new ExpressMessage();
m.setSendName(rs.getString(1));
m.setSendTelephone(rs.getString(2));
m.setSendCompary(rs.getString(3));
m.setSendAddress(rs.getString(4));
m.setSendPostcode(rs.getString(5));
m.setReceiveName(rs.getString(6));
m.setReceiveTelephone(rs.getString(7));
m.setReceiveCompary(rs.getString(8));
m.setReceiveAddress(rs.getString(9));
m.setReceivePostcode(rs.getString(10));
m.setControlPosition(rs.getString(11));
m.setExpressSize(rs.getString(12));
v.add(m);
}
return v;
} catch (Exception ex) {
ex.printStackTrace();
return null;
} finally {
try {
if(ps != null) {
ps.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static Vector<ExpressMessage> queryAllExpress() {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DAO.getConn();
ps = conn.prepareStatement("select id,sendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,receiveTelephone,receiveCompary,receiveAddress,receivePostcode,"
+ "ControlPosition,expressSize from tb_receiveSendMessage");
ResultSet rs = ps.executeQuery();
Vector<ExpressMessage> v = new Vector<ExpressMessage>();
while(rs.next()) {
ExpressMessage m = new ExpressMessage();
m.setId(rs.getInt(1));
m.setSendName(rs.getString(2));
m.setSendTelephone(rs.getString(3));
m.setSendCompary(rs.getString(4));
m.setSendAddress(rs.getString(5));
m.setSendPostcode(rs.getString(6));
m.setReceiveName(rs.getString(7));
m.setReceiveTelephone(rs.getString(8));
m.setReceiveCompary(rs.getString(9));
m.setReceiveAddress(rs.getString(10));
m.setReceivePostcode(rs.getString(11));
m.setControlPosition(rs.getString(12));
m.setExpressSize(rs.getString(13));
v.add(m);
}
return v;
} catch (Exception ex) {
ex.printStackTrace();
return null;
} finally {
try {
if(ps != null) {
ps.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
UserDao.java
package com.zzk.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.zzk.bean.User;
import com.zzk.tool.SaveUserStateTool;
public class UserDao {
/*
* 判断用户名和密码的方法
* @param user 实体类User的实例
*/
public static boolean okUser(User user) {
Connection conn = null;
try {
String username = user.getName();
String pwd = user.getPwd();
conn = DAO.getConn();
PreparedStatement ps = conn.prepareStatement("select password from tb_user where username=?");
ps.setString(1, username);
ResultSet rs = ps.executeQuery();
if(rs.next()&&rs.getRow()>0) {
String password = rs.getString(1);
if(password.equals(pwd)) {
SaveUserStateTool.setUsername(username);
SaveUserStateTool.setPassword(pwd);
return true;
} else {
JOptionPane.showMessageDialog(null,"密码不正确。");
return false;
}
} else {
JOptionPane.showMessageDialog(null,"用户名不存在。");
return false;
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "数据库异常!\n" + ex.getMessage());
return false;
} finally {
if(conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
/*
* this method is initializes insertUser
* @param user
*/
public static void insertUser(User user) {
Connection conn = null;
try {
String username = user.getName();
String pwd = user.getPwd();
String okPwd = user.getOkPwd();
if(username == null || username.trim().equals("") || pwd == null || pwd.trim().equals("") || okPwd == null || okPwd.trim().equals("")) {
JOptionPane.showMessageDialog(null, "用户名或密码不能为空");
return ;
}
if(!pwd.trim().equals(okPwd.trim())) {
JOptionPane.showMessageDialog(null, "两次输入的密码不一致");
return ;
}
conn = DAO.getConn();
PreparedStatement ps = conn.prepareStatement("insert into tb_user (username,password) values(?,?)");
ps.setString(1, username.trim());
ps.setString(2, pwd.trim());
int flag = ps.executeUpdate();
/*
System.out.println("first: " + username.trim() + " second: " + pwd.trim());
try {
int flag = ps.executeUpdate();
System.out.println("2");
conn.commit();
} catch (Exception ex) {
ex.printStackTrace();
}
*/
if(flag > 0) {
JOptionPane.showMessageDialog(null, "添加成功");
} else {
JOptionPane.showMessageDialog(null, "添加失败");
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "用户名重复,请换个名称!");
return ;
} finally {
try {
if(conn != null) {
conn.close();
}
} catch (Exception ex) {
}
}
}
/*
* this method is updateUser
* @return void
*/
public static void updateUser(String oldPwd, String newPwd, String okPwd) {
try {
if(!newPwd.trim().equals(okPwd.trim())) {
JOptionPane.showMessageDialog(null, "两次输入的密码不一致");
return ;
}
if(!oldPwd.trim().equals(SaveUserStateTool.getPassword())) {
JOptionPane.showMessageDialog(null, "原密码不正确");
return ;
}
Connection conn = DAO.getConn();
PreparedStatement ps = conn.prepareStatement("update tb_user set password = ? where username = ?");
ps.setString(1, newPwd.trim());
ps.setString(2, SaveUserStateTool.getUsername());
int flag = ps.executeUpdate();
if(flag > 0) {
JOptionPane.showMessageDialog(null, "修改成功");
} else {
JOptionPane.showMessageDialog(null, "修改失败");
}
ps.close();
conn.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "数据库异常!!" + ex.getMessage());
return ;
}
}
}
com.zzk.frame
AddExpressFrame.java
package com.zzk.frame;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.zzk.bean.ExpressMessage;
import com.zzk.dao.ExpressMessageDao;
import com.zzk.panel.BackgroundPanel;
public class AddExpressFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private URL url = null;
private Image image = null;
private BackgroundPanel jPanel = null;
private JTextField tf_sendName = null;
private JTextField tf_sendTelephone = null;
private JTextField tf_sendCompany = null;
private JTextField tf_sendAddress1 = null;
private JTextField tf_sendAddress2 = null;
private JTextField tf_sendAddress3 = null;
private JTextField tf_sendPostcode = null;
private JTextField tf_receiveName = null;
private JTextField tf_receiveTelephone = null;
private JTextField tf_receiveCompany = null;
private JTextField tf_receiveAddress1 = null;
private JTextField tf_receiveAddress2 = null;
private JTextField tf_receiveAddress3 = null;
private JTextField tf_receivePostcode = null;
private JPanel jPanel1 = null;
private JButton btn_clear = null;
private JButton btn_save = null;
private JButton btn_return = null;
/*
* this method initializes jPanel1
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if(jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new FlowLayout());
jPanel1.add(getBtn_clear(),null);
jPanel1.add(getBtn_save(),null);
jPanel1.add(getBtn_return(),null);
}
return jPanel1;
}
/*
* this method initializes btn_clear
* @return javax.swing.JButton
*/
private JButton getBtn_clear() {
if(btn_clear == null) {
btn_clear = new JButton();
btn_clear.setText("清 空");
btn_clear.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
tf_sendName.setText(null);
tf_sendTelephone.setText(null);
tf_sendCompany.setText(null);
tf_sendAddress1.setText(null);
tf_sendAddress2.setText(null);
tf_sendAddress3.setText(null);
tf_sendPostcode.setText(null);
tf_receiveName.setText(null);
tf_receiveTelephone.setText(null);
tf_receiveCompany.setText(null);
tf_receiveAddress1.setText(null);
tf_receiveAddress2.setText(null);
tf_receiveAddress3.setText(null);
tf_receivePostcode.setText(null);
tf_sendName.requestFocus();
}
});
}
return btn_clear;
}
/*
* this method initializes btn_save
* @return javax.swing.JButton
*/
private JButton getBtn_save() {
if(btn_save == null) {
btn_save = new JButton();
btn_save.setText("保 存");
btn_save.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
StringBuffer buffer = new StringBuffer();
ExpressMessage m = new ExpressMessage();
m.setSendName(tf_sendName.getText().trim());
m.setSendTelephone(tf_sendTelephone.getText().trim());
m.setSendCompary(tf_sendCompany.getText().trim());
m.setSendAddress(tf_sendAddress1.getText().trim() + "|" +
tf_sendAddress2.getText().trim() + "|" + tf_sendAddress3.getText().trim());
m.setSendPostcode(tf_sendPostcode.getText().trim());
m.setReceiveName(tf_receiveName.getText().trim());
m.setReceiveTelephone(tf_receiveTelephone.getText().trim());
m.setReceiveCompary(tf_receiveCompany.getText().trim());
m.setReceiveAddress(tf_receiveAddress1.getText().trim() + "|" +
tf_receiveAddress2.getText().trim() + "|" + tf_receiveAddress3.getText().trim());
m.setReceivePostcode(tf_receivePostcode.getText().trim());
buffer.append(tf_sendName.getX() + "," + tf_sendName.getY() + "/");
buffer.append(tf_sendTelephone.getX() + "," + tf_sendTelephone.getY() + "/");
buffer.append(tf_sendCompany.getX() + "," + tf_sendCompany.getY() + "/");
buffer.append(tf_sendAddress1.getX() + "," + tf_sendAddress1.getY() + "/");
buffer.append(tf_sendAddress2.getX() + "," + tf_sendAddress2.getY() + "/");
buffer.append(tf_sendAddress3.getX() + "," + tf_sendAddress3.getY() + "/");
buffer.append(tf_sendPostcode.getX() + "," + tf_sendPostcode.getY() + "/");
buffer.append(tf_receiveName.getX() + "," + tf_receiveName.getY() + "/");
buffer.append(tf_receiveTelephone.getX() + "," + tf_receiveTelephone.getY() + "/");
buffer.append(tf_receiveCompany.getX() + "," + tf_receiveCompany.getY() + "/");
buffer.append(tf_receiveAddress1.getX() + "," + tf_receiveAddress1.getY() + "/");
buffer.append(tf_receiveAddress2.getX() + "," + tf_receiveAddress2.getY() + "/");
buffer.append(tf_receiveAddress3.getX() + "," + tf_receiveAddress3.getY() + "/");
buffer.append(tf_receivePostcode.getX() + "," + tf_receivePostcode.getY() + "/");
m.setControlPosition(new String(buffer));
m.setExpressSize(jPanel.getWidth() + "," + jPanel.getHeight());
ExpressMessageDao.insertExpress(m);
}
});
}
return btn_save;
}
/*
* this method initializes btn_return
* @return javax.swing.JButton
*/
private JButton getBtn_return() {
if(btn_return == null) {
btn_return = new JButton();
btn_return.setText("返 回");
btn_return.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return btn_return;
}
/*
* @param owner
*/
public AddExpressFrame() {
super();
initializes();
}
/*
* this method initializes this
* @return void
*/
public void initializes() {
this.setSize(1017, 584);
this.setTitle("添加快递信息");
this.setContentPane(getJContentPane());
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(),BorderLayout.CENTER);
jContentPane.add(getJPanel1(),BorderLayout.SOUTH);
}
return jContentPane;
}
/*
* this method initializes jPanel
* @return javax.swing.JPanel
*/
private BackgroundPanel getJPanel() {
if(jPanel == null) {
url = AddExpressFrame.class.getResource("expresso4.jpg");
image = new ImageIcon(url).getImage();
jPanel = new BackgroundPanel(image);
jPanel.setLayout(null);
jPanel.add(getTf_sendName(),null);
jPanel.add(getTf_sendTelephone(),null);
jPanel.add(getTf_sendCompany(),null);
jPanel.add(getTf_sendAddress1(),null);
jPanel.add(getTf_sendAddress2(),null);
jPanel.add(getTf_sendAddress3(),null);
jPanel.add(getTf_sendPostcode(),null);
jPanel.add(getTf_receiveName(),null);
jPanel.add(getTf_receiveTelephone(),null);
jPanel.add(getTf_receiveCompany(),null);
jPanel.add(getTf_receiveAddress1(),null);
jPanel.add(getTf_receiveAddress2(),null);
jPanel.add(getTf_receiveAddress3(),null);
jPanel.add(getTf_receivePostcode(),null);
}
return jPanel;
}
/*
* this method initializes tf_sendName
* @return javax.swing.JTextField
*/
private JTextField getTf_sendName() {
if(tf_sendName == null) {
tf_sendName = new JTextField();
tf_sendName.setBounds(new Rectangle(150,114,139,22));
}
return tf_sendName;
}
/*
* this method initializes tf_sendTelephone
* @return javax.swing.JTextField
*/
private JTextField getTf_sendTelephone() {
if(tf_sendTelephone == null) {
tf_sendTelephone = new JTextField();
tf_sendTelephone.setBounds(new Rectangle(347,114,131,22));
}
return tf_sendTelephone;
}
/*
* this method initializes tf_sendCompany
* @return javax.swing.JTextField
*/
private JTextField getTf_sendCompany() {
if(tf_sendCompany == null) {
tf_sendCompany = new JTextField();
tf_sendCompany.setBounds(new Rectangle(150,141,328,22));
}
return tf_sendCompany;
}
/*
* this method initializes tf_sendAddress1
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress1() {
if(tf_sendAddress1 == null) {
tf_sendAddress1 = new JTextField();
tf_sendAddress1.setBounds(new Rectangle(115,179,362,22));
}
return tf_sendAddress1;
}
/*
* this method initializes tf_sendAddress2
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress2() {
if(tf_sendAddress2 == null) {
tf_sendAddress2 = new JTextField();
tf_sendAddress2.setBounds(new Rectangle(114,205,362,22));
}
return tf_sendAddress2;
}
/*
* this method initializes tf_sendAddress3
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress3() {
if(tf_sendAddress3 == null) {
tf_sendAddress3 = new JTextField();
tf_sendAddress3.setBounds(new Rectangle(114,230,361,22));
}
return tf_sendAddress3;
}
/*
* this method initializes tf_sendPostcode
* @return javax.swing.JTextField
*/
private JTextField getTf_sendPostcode() {
if(tf_sendPostcode == null) {
tf_sendPostcode = new JTextField();
tf_sendPostcode.setBounds(new Rectangle(366,256,109,22));
}
return tf_sendPostcode;
}
/*
* this method initializes tf_receiveName
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveName() {
if(tf_receiveName == null) {
tf_receiveName = new JTextField();
tf_receiveName.setBounds(new Rectangle(151,311,142,22));
}
return tf_receiveName;
}
/*
* this method initializes tf_receiveTelephone
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveTelephone() {
if(tf_receiveTelephone == null) {
tf_receiveTelephone = new JTextField();
tf_receiveTelephone.setBounds(new Rectangle(349,312,126,22));
}
return tf_receiveTelephone;
}
/*
* this method initializes tf_receiveCompany
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveCompany() {
if(tf_receiveCompany == null) {
tf_receiveCompany = new JTextField();
tf_receiveCompany.setBounds(new Rectangle(150,339,325,22));
}
return tf_receiveCompany;
}
/*
* this method initializes tf_receiveAddress1
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress1() {
if(tf_receiveAddress1 == null) {
tf_receiveAddress1 = new JTextField();
tf_receiveAddress1.setBounds(new Rectangle(115,377,363,22));
}
return tf_receiveAddress1;
}
/*
* this method initializes tf_receiveAddress2
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress2() {
if(tf_receiveAddress2 == null) {
tf_receiveAddress2 = new JTextField();
tf_receiveAddress2.setBounds(new Rectangle(115,404,362,22));
}
return tf_receiveAddress2;
}
/*
* this method initializes tf_receiveAddress3
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress3() {
if(tf_receiveAddress3 == null) {
tf_receiveAddress3 = new JTextField();
tf_receiveAddress3.setBounds(new Rectangle(116,430,362,22));
}
return tf_receiveAddress3;
}
/*
* this method initializes tf_receivePostcode
* @return javax.swing.JTextField
*/
private JTextField getTf_receivePostcode() {
if(tf_receivePostcode == null) {
tf_receivePostcode = new JTextField();
tf_receivePostcode.setBounds(new Rectangle(366,456,112,22));
}
return tf_receivePostcode;
}
}
AddUserFrame.java
package com.zzk.frame;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.zzk.bean.User;
import com.zzk.dao.UserDao;
public class AddUserFrame extends JFrame {
// private static final long serivalVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField tf_user = null;
private JPasswordField pf_pwd = null;
private JPasswordField pf_okPwd = null;
private JButton btn_save = null;
private JButton btn_return = null;
/*
* this is the default constructor
*/
public AddUserFrame() {
super();
initialize();
}
/*
* this method initializes this
* @return void
*/
private void initialize() {
this.setSize(300,190);
this.setContentPane(getJContentPane());
this.setTitle("添加用户");
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(26,80,69,18));
jLabel2.setText("确认密码:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(34,49,44,18));
jLabel1.setText("密码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(33,18,45,18));
jLabel.setText("用户:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,null);
jContentPane.add(jLabel1,null);
jContentPane.add(jLabel2,null);
jContentPane.add(getTf_user(),null);
jContentPane.add(getPf_pwd(),null);
jContentPane.add(getPf_okPwd(),null);
jContentPane.add(getBtn_save(),null);
jContentPane.add(getBtn_return(),null);
}
return jContentPane;
}
/*
* this method initializes tf_user
* @return javax.swing.JTextField
*/
private JTextField getTf_user() {
if(tf_user == null) {
tf_user = new JTextField();
tf_user.setBounds(new Rectangle(95,18,166,22));
}
return tf_user;
}
/*
* this method initializes pf_pwd
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_pwd() {
if(pf_pwd == null) {
pf_pwd = new JPasswordField();
pf_pwd.setBounds(new Rectangle(95,49,164,22));
pf_pwd.setEchoChar('*');
}
return pf_pwd;
}
/*
* this method initializes pf_okPwd
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_okPwd() {
if(pf_okPwd == null) {
pf_okPwd = new JPasswordField();
pf_okPwd.setBounds(new Rectangle(96,78,164,22));
pf_okPwd.setEchoChar('*');
}
return pf_okPwd;
}
/*
* this method initializes btn_save
* @return javax.swing.JButton
*/
private JButton getBtn_save() {
if(btn_save == null) {
btn_save = new JButton();
btn_save.setBounds(new Rectangle(41,111,84,23));
btn_save.setText("保 存");
btn_save.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
String username = tf_user.getText().trim();
String password = new String(pf_pwd.getPassword());
String okPassword = new String(pf_okPwd.getPassword());
User user = new User();
user.setName(username);
user.setPwd(password);
user.setOkPwd(okPassword);
UserDao.insertUser(user);
}
});
}
return btn_save;
}
/*
* this method initializes btn_return
* @return javax.swing.JButton
*/
private JButton getBtn_return() {
if(btn_return == null) {
btn_return = new JButton();
btn_return.setBounds(new Rectangle(151,110,85,23));
btn_return.setText("返 回");
btn_return.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return btn_return;
}
}
LoginFrame.java
package com.zzk.frame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import com.zzk.bean.User;
import com.zzk.dao.UserDao;
import com.zzk.panel.BackgroundPanel;
public class LoginFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private URL url = null;//声明图片的URL
private Image image = null;
private BackgroundPanel jPanel = null;//声明自定义背景面板对象
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField tf_username = null;//用户名
private JPasswordField pf_password = null;//密码
private JButton btn_login =null;//登录
private JButton btn_reset = null;//重置
private JButton btn_exit = null;//退出
private JPanel getJPanel() {
if(jPanel == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(221, 176, 63, 18));
jLabel1.setText("密 码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(220, 141, 63, 18));
jLabel.setText("用 户:");
url = UpdateExpressFrame.class.getResource("expresso3.jpg");//获得图片的url
image = new ImageIcon(url).getImage();//创建图像对象
jPanel = new BackgroundPanel(image);
jPanel.setLayout(null);
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getTf_username(), null);
jPanel.add(getPf_password(), null);
jPanel.add(getBtn_login(),null);
jPanel.add(getBtn_reset(),null);
jPanel.add(getBtn_exit(),null);
}
return jPanel;
}
/*
This method initializes tf_username
@return javax.swing.JTextField
*/
private JTextField getTf_username() {
if(tf_username == null) {
tf_username = new JTextField();
tf_username.setBounds(new Rectangle(290,140,143,22));
tf_username.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_password.requestFocus();
}
});
}
return tf_username;
}
/*
* this method initializes pf_password
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_password() {
if(pf_password == null) {
pf_password = new JPasswordField();
pf_password.setBounds(new Rectangle(290,175,141,22));
pf_password.setEchoChar('*');
pf_password.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_password.requestFocus();
/*
String username = tf_username.getText().trim();
String password = new String(pf_password.getPassword());
User user = new User();
user.setName(username);
user.setPwd(password);
if(UserDao.okUser(user)) {
MainFrame thisClass = new MainFrame();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height - thisClass.getHeight())/2);
thisClass.setVisible(true);
dispose();
}
*/
}
});
}
return pf_password;
}
/*
* this method initializes btn_login
* @return javax.swing.JButton
*/
private JButton getBtn_login() {
if(btn_login == null) {
btn_login = new JButton();
btn_login.setText("登 录");
btn_login.setBounds(new Rectangle(221,211,56,22));
//btn_login.setRolloverIcon(new ImageIcon(getClass().getResource("buttonTwo.jpg")));
//btn_login.setIcon(new ImageIcon(getClass().getResource("buttonOne.jpg")));
btn_login.setMargin(new Insets(0,0,0,0));
btn_login.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
String username = tf_username.getText().trim();
String password = new String(pf_password.getPassword());
User user = new User();
user.setName(username);
user.setPwd(password);
if(UserDao.okUser(user)) {
MainFrame thisClass = new MainFrame();
thisClass.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
dispose();
}
}
});
}
return btn_login;
}
/*
* this method initializes btn_reset
* @return javax.swing.JButton
*/
private JButton getBtn_reset() {
if(btn_reset == null) {
btn_reset = new JButton();
btn_reset.setText("重 置");
btn_reset.setBounds(new Rectangle(299,211,55,23));
//btn_reset.setRolloverIcon(new ImageIcon(getClass().getResource("buttonTwo.jpg")));
//btn_reset.setIcon(new ImageIcon(getClass().getResource("buttonOne.jpg")));
btn_reset.setMargin(new Insets(0,0,0,0));
btn_reset.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
tf_username.setText("");
pf_password.setText("");
tf_username.requestFocus();
}
});
}
return btn_reset;
}
/*
* this method initializes btn_exit
* @return javax.swing.JButton
*/
public JButton getBtn_exit() {
if(btn_exit == null) {
btn_exit = new JButton();
btn_exit.setText("退 出");
btn_exit.setBounds(new Rectangle(374,211,53,22));
//btn_exit.setRolloverIcon(new ImageIcon(getClass().getResource("buttonTwo.jpg")));
//btn_exit.setIcon(new ImageIcon(getClass().getResource("buttonOne.jpg")));
btn_exit.setMargin(new Insets(0,0,0,0));
btn_exit.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return btn_exit;
}
/*
* @param args
*/
public static void main(String[] args) {
//TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LoginFrame thisClass = new LoginFrame();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit toolkit = thisClass.getToolkit();
Dimension dm = toolkit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2, (dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
}
});
}
/*
* this is the default constructor
*/
public LoginFrame() {
super();
initialize();
}
/*
* this method initializes this
* @return void
*/
private void initialize() {
this.setSize(476,301);
this.setContentPane(getJContentPane());
this.setTitle("系统登录");
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(),BorderLayout.CENTER);
}
return jContentPane;
}
}
MainFrame.java
package com.zzk.frame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import com.zzk.panel.*;
public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private URL url = null;
private Image image = null;
private BackgroundPanel jPanel = null;
private JMenuBar jJMenuBar = null;
private JMenu jMenu = null;//快递单管理 0 2
private JMenu jMenu1 = null;//打印管理 3
private JMenu jMenu2 = null;//系统 1 4 5
private JMenuItem jMenuItem = null;//添加快递单
private JMenuItem jMenuItem1 = null;//添加用户
private JMenuItem jMenuItem2 = null;//修改快递单
private JMenuItem jMenuItem3 = null;//打印快递单
private JMenuItem jMenuItem4 = null;//修改用户密码
private JMenuItem jMenuItem5 = null;//退出系统
/*
* @param owner
*/
public MainFrame() {
super();
initialize();
}
/*
* this method initializes this
* @return void
*/
private void initialize() {
this.setSize(1017,584);
this.setJMenuBar(getjJMenuBar());
this.setTitle("EMS快递打印系统");
this.setContentPane(getJContentPane());
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(),BorderLayout.CENTER);
}
return jContentPane;
}
/*
* this method initializes jPanel
* @return javax.swing.JPanel
*/
private BackgroundPanel getJPanel() {
if(jPanel == null) {
url = MainFrame.class.getResource("express.jpg");
image = new ImageIcon(url).getImage();
jPanel = new BackgroundPanel(image);
jPanel.setLayout(null);
}
return jPanel;
}
/*
* this method initializes jJMenuBar
* @return javax.swing.JMenuBar
*/
private JMenuBar getjJMenuBar() {
if(jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getJMenu());
jJMenuBar.add(getJMenu1());
jJMenuBar.add(getJMenu2());
}
return jJMenuBar;
}
/*
*this method initializes jMenu
*@return javax.swing.JMenu
*/
private JMenu getJMenu() {
if(jMenu == null) {
jMenu = new JMenu();
jMenu.setText("快递单管理");
jMenu.add(getJMenuItem());
jMenu.add(getJMenuItem2());
}
return jMenu;
}
/*
* this method initializes jMenuItem
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem() {
if(jMenuItem == null) {
jMenuItem = new JMenuItem();
jMenuItem.setText("添加快递单");
jMenuItem.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
AddExpressFrame thisClass = new AddExpressFrame();
thisClass.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
}
});
}
return jMenuItem;
}
/*
* this method initializes jMenuItem2
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem2() {
if(jMenuItem2 == null) {
jMenuItem2 = new JMenuItem();
jMenuItem2.setText("修改快递单");
jMenuItem2.addActionListener(new java.awt.event.ActionListener(){
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
UpdateExpressFrame thisClass = new UpdateExpressFrame();
thisClass.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
}
});
}
return jMenuItem2;
}
/*
* this method initializes jMenu1
* @return javax.swing.JMenu
*/
private JMenu getJMenu1() {
if(jMenu1 == null) {
jMenu1 = new JMenu();
jMenu1.setText("打印管理");
jMenu1.add(getJMenuItem3());
}
return jMenu1;
}
/*
* this method initializes jMenu2
* @return javax.swing.JMenu
*/
private JMenu getJMenu2() {
if(jMenu2 == null) {
jMenu2 = new JMenu();
jMenu2.setText("系统");
jMenu2.add(getJMenuItem1());
jMenu2.add(getJMenuItem4());
jMenu2.add(getJMenuItem5());
}
return jMenu2;
}
/*
* this method initializes jMenuItem3
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem3() {
if(jMenuItem3 == null) {
jMenuItem3 = new JMenuItem();
jMenuItem3.setText("打印快递单");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
PrintAndPrintSetFrame thisClass = new PrintAndPrintSetFrame();
thisClass.setDefaultCloseOperation1(WindowConstants.DISPOSE_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit1();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height - thisClass.getHeight())/2);
thisClass.setVisible1(true);
}
});
}
return jMenuItem3;
}
/*
* this method initializes jMenuItem4
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem4() {
if(jMenuItem4 == null) {
jMenuItem4 = new JMenuItem();
jMenuItem4.setText("修改用户密码");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
UpdateUserPasswordFrame thisClass = new UpdateUserPasswordFrame();
thisClass.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
}
});
}
return jMenuItem4;
}
/*
* this method initializes jMenuItem5
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem5() {
if(jMenuItem5 == null) {
jMenuItem5 = new JMenuItem();
jMenuItem5.setText("退出系统");
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return jMenuItem5;
}
/*
* this method initializes jMenuItem1
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem1() {
if(jMenuItem1 == null) {
jMenuItem1 = new JMenuItem();
jMenuItem1.setText("添加用户");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
AddUserFrame thisClass = new AddUserFrame();
thisClass.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Toolkit tookit = thisClass.getToolkit();
Dimension dm = tookit.getScreenSize();
thisClass.setLocation((dm.width-thisClass.getWidth())/2,(dm.height-thisClass.getHeight())/2);
thisClass.setVisible(true);
}
});
}
return jMenuItem1;
}
}
PrintAndPrintSetFrame.java
package com.zzk.frame;
import java.awt.Toolkit;
import java.util.Vector;
import javax.swing.JOptionPane;
import com.zzk.bean.ExpressMessage;
import com.zzk.dao.ExpressMessageDao;
public class PrintAndPrintSetFrame {
public PrintAndPrintSetFrame() {
JOptionPane.showMessageDialog(null, "快递单正在打印中,请从出风口处取走您的快递单......");
}
public void setDefaultCloseOperation(int disposeOnClose) {
// TODO Auto-generated method stub
}
public Toolkit getToolkit() {
// TODO Auto-generated method stub
return null;
}
public void setVisible(boolean b) {
// TODO Auto-generated method stub
}
public Toolkit getToolkit1() {
// TODO Auto-generated method stub
return null;
}
public void setDefaultCloseOperation1(int disposeOnClose) {
// TODO Auto-generated method stub
}
public int getWidth() {
// TODO Auto-generated method stub
return 0;
}
public void setVisible1(boolean b) {
// TODO Auto-generated method stub
}
public void setLocation(int i, int j) {
// TODO Auto-generated method stub
}
public int getHeight() {
// TODO Auto-generated method stub
return 0;
}
}
UpdateExpressFrame.java
package com.zzk.frame;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.net.URL;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.zzk.bean.ExpressMessage;
import com.zzk.dao.ExpressMessageDao;
import com.zzk.panel.BackgroundPanel;
public class UpdateExpressFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private URL url = null;
private Image image = null;
private BackgroundPanel jPanel = null;
private JTextField tf_sendName = null;
private JTextField tf_sendTelephone = null;
private JTextField tf_sendCompany = null;
private JTextField tf_sendAddress1 = null;
private JTextField tf_sendAddress2 = null;
private JTextField tf_sendAddress3 = null;
private JTextField tf_sendPostcode = null;
private JTextField tf_receiveName = null;
private JTextField tf_receiveTelephone = null;
private JTextField tf_receiveCompany = null;
private JTextField tf_receiveAddress1 = null;
private JTextField tf_receiveAddress2 = null;
private JTextField tf_receiveAddress3 = null;
private JTextField tf_receivePostcode = null;
private JPanel jPanel1 = null;
private JButton btn_pre = null;
private JButton btn_next = null;
private JButton btn_update = null;
private JButton jButton2 = null;
private int queryRow = -1;
private Vector<ExpressMessage> queryResultVector = null;
private String controlPosition = null;
private String expressSize = null;
private int id;
/*
* this method initializes jPanel1
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if(jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new FlowLayout());
jPanel1.add(getBtn_pre(),null);
jPanel1.add(getBtn_next(),null);
jPanel1.add(getBtn_update(),null);
jPanel1.add(getJButton2(),null);
}
return jPanel1;
}
/*
* this method initializes btn_next
* @return javax.swing.JButton
*/
private JButton getBtn_next() {
if(btn_next == null) {
btn_next = new JButton();
btn_next.setText("下一条");
btn_next.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
//queryResultVector = ExpressMessageDao.queryExpress();
if(queryResultVector != null) {
queryRow++;
if(queryRow > queryResultVector.size()-1) {
queryRow = queryResultVector.size()-1;
JOptionPane.showMessageDialog(null, "已经是最后一条信息。");
}
ExpressMessage m = queryResultVector.get(queryRow);
id = m.getId();
showResultValue(m);
}
}
});
}
return btn_next;
}
/*
* this method initializes btn_pre
* @return javax.swing.JButton
*/
private JButton getBtn_pre() {
if(btn_pre == null) {
btn_pre = new JButton();
btn_pre.setText("上一条");
btn_pre.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
//queryResultVector = ExpressMessageDao.queryExpress();
if(queryResultVector != null) {
queryRow--;
if(queryRow < 0) {
queryRow = 0;
JOptionPane.showMessageDialog(null, "已经是第一条信息。");
}
ExpressMessage m = queryResultVector.get(queryRow);
id = m.getId();
showResultValue(m);
}
}
});
}
return btn_pre;
}
/*
* this method initializes btn_update
* @return javax.swing.JButton
*/
private JButton getBtn_update() {
if(btn_update == null) {
btn_update = new JButton();
btn_update.setText("修改");
btn_update.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
StringBuffer buffer = new StringBuffer();
ExpressMessage m = new ExpressMessage();
m.setId(id);
m.setSendName(tf_sendName.getText().trim());
m.setSendTelephone(tf_sendTelephone.getText().trim());
m.setSendCompary(tf_sendCompany.getText().trim());
m.setSendAddress(tf_sendAddress1.getText().trim() + "|" + tf_sendAddress2.getText().trim() + "|" + tf_sendAddress3.getText().trim());
m.setSendPostcode(tf_sendPostcode.getText().trim());
m.setReceiveName(tf_receiveName.getText().trim());
m.setReceiveTelephone(tf_receiveTelephone.getText().trim());
m.setReceiveCompary(tf_receiveCompany.getText().trim());
m.setReceiveAddress(tf_receiveAddress1.getText().trim() + "|" +
tf_receiveAddress2.getText().trim() + "|" + tf_receiveAddress3.getText().trim());
m.setReceivePostcode(tf_receivePostcode.getText().trim());
buffer.append(tf_sendName.getX() + "," + tf_sendName.getY() + "/");
buffer.append(tf_sendTelephone.getX() + "," + tf_sendTelephone.getY() + "/");
buffer.append(tf_sendCompany.getX() + "," + tf_sendCompany.getY() + "/");
buffer.append(tf_sendAddress1.getX() + "," + tf_sendAddress1.getY() + "/");
buffer.append(tf_sendAddress2.getX() + "," + tf_sendAddress2.getY() + "/");
buffer.append(tf_sendAddress3.getX() + "," + tf_sendAddress3.getY() + "/");
buffer.append(tf_sendPostcode.getX() + "," + tf_sendPostcode.getY() + "/");
buffer.append(tf_receiveName.getX() + "," + tf_receiveName.getY() + "/");
buffer.append(tf_receiveTelephone.getX() + "," + tf_receiveTelephone.getY() + "/");
buffer.append(tf_receiveCompany.getX() + "," + tf_receiveCompany.getY() + "/");
buffer.append(tf_receiveAddress1.getX() + "," + tf_receiveAddress1.getY() + "/");
buffer.append(tf_receiveAddress2.getX() + "," + tf_receiveAddress2.getY() + "/");
buffer.append(tf_receiveAddress3.getX() + "," + tf_receiveAddress3.getY() + "/");
buffer.append(tf_receivePostcode.getX() + "," + tf_receivePostcode.getY());
m.setControlPosition(new String(buffer));
m.setExpressSize(jPanel.getWidth() + "," + jPanel.getHeight());
ExpressMessageDao.updateExpress(m);
queryResultVector = ExpressMessageDao.queryAllExpress();
if(queryResultVector != null) {
m = queryResultVector.get(queryRow);
}
}
});
}
return btn_update;
}
/*
* this method initializes jButton2
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if(jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("返 回");
jButton2.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return jButton2;
}
/*
* @param owner
*/
public UpdateExpressFrame() {
super();
initialize();
}
/*
* this method initializes this
* @return void
*/
private void initialize() {
this.setSize(1017, 584);
this.setTitle("修改快递信息");
this.setContentPane(getJContentPane());
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowOpened(java.awt.event.WindowEvent e) {
queryResultVector = ExpressMessageDao.queryAllExpress();
if(queryResultVector != null) {
queryRow++;
ExpressMessage m = queryResultVector.get(queryRow);
id = m.getId();
showResultValue(m);
}
}
});
}
private void showResultValue(ExpressMessage m) {
id = m.getId();
tf_sendName.setText(m.getSendName());
tf_sendTelephone.setText(m.getSendTelephone());
tf_sendCompany.setText(m.getSendCompary());
String addressValue1 = m.getSendAddress();
tf_sendAddress1.setText(addressValue1.substring(0,addressValue1.indexOf("|")));
tf_sendAddress2.setText(addressValue1.substring(addressValue1.indexOf("|")+1, addressValue1.lastIndexOf("|")));
tf_sendAddress3.setText(addressValue1.substring(addressValue1.lastIndexOf("|") + 1));
tf_sendPostcode.setText(m.getSendPostcode());
tf_receiveName.setText(m.getReceiveName());
tf_receiveTelephone.setText(m.getReceiveTelephone());
tf_receiveCompany.setText(m.getReceiveCompary());
String addressValue2 = m.getReceiveAddress();
tf_receiveAddress1.setText(addressValue2.substring(0, addressValue2.indexOf("|")));
tf_receiveAddress2.setText(addressValue2.substring(addressValue2.indexOf("|") + 1,addressValue2.lastIndexOf("|")));
tf_receiveAddress3.setText(addressValue2.substring(addressValue2.lastIndexOf("|")+1));
tf_receivePostcode.setText(m.getReceivePostcode());
controlPosition = m.getControlPosition();
expressSize = m.getExpressSize();
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(),BorderLayout.CENTER);
jContentPane.add(getJPanel1(),BorderLayout.SOUTH);
}
return jContentPane;
}
/*
* this method initializes jPanel
* @return javax.swing.JPanel
*/
private BackgroundPanel getJPanel() {
if(jPanel == null) {
url = UpdateExpressFrame.class.getResource("expresso4.jpg");
image = new ImageIcon(url).getImage();
jPanel = new BackgroundPanel(image);
jPanel.setLayout(null);
jPanel.add(getTf_sendName(),null);
jPanel.add(getTf_sendTelephone(),null);
jPanel.add(getTf_sendCompany(),null);
jPanel.add(getTf_sendAddress1(),null);
jPanel.add(getTf_sendAddress2(),null);
jPanel.add(getTf_sendAddress3(),null);
jPanel.add(getTf_sendPostcode(),null);
jPanel.add(getTf_receiveName(),null);
jPanel.add(getTf_receiveTelephone(),null);
jPanel.add(getTf_receiveCompany(),null);
jPanel.add(getTf_receiveAddress1(),null);
jPanel.add(getTf_receiveAddress2(),null);
jPanel.add(getTf_receiveAddress3(),null);
jPanel.add(getTf_receivePostcode(),null);
}
return jPanel;
}
/*
* this method initializes tf_sendName
* @return javax.swing.JTextField
*/
private JTextField getTf_sendName() {
if(tf_sendName == null) {
tf_sendName = new JTextField();
tf_sendName.setBounds(new Rectangle(150,114,139,22));
}
return tf_sendName;
}
/*
* this method initializes tf_sendTelephone
* @return javax.swing.JTextField
*/
private JTextField getTf_sendTelephone() {
if(tf_sendTelephone == null) {
tf_sendTelephone = new JTextField();
tf_sendTelephone.setBounds(new Rectangle(347,114,131,22));
}
return tf_sendTelephone;
}
/*
* this method initializes tf_sendCompany
* @return javax.swing.JTextField
*/
private JTextField getTf_sendCompany() {
if(tf_sendCompany == null) {
tf_sendCompany = new JTextField();
tf_sendCompany.setBounds(new Rectangle(150,141,328,22));
}
return tf_sendCompany;
}
/*
* this method initializes tf_sendAddress1
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress1() {
if(tf_sendAddress1 == null) {
tf_sendAddress1 = new JTextField();
tf_sendAddress1.setBounds(new Rectangle(115,179,362,22));
}
return tf_sendAddress1;
}
/*
* this method initializes tf_sendAddress2
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress2() {
if(tf_sendAddress2 == null) {
tf_sendAddress2 = new JTextField();
tf_sendAddress2.setBounds(new Rectangle(114,205,362,22));
}
return tf_sendAddress2;
}
/*
* this method initializes tf_sendAddress3
* @return javax.swing.JTextField
*/
private JTextField getTf_sendAddress3() {
if(tf_sendAddress3 == null) {
tf_sendAddress3 = new JTextField();
tf_sendAddress3.setBounds(new Rectangle(114,230,361,22));
}
return tf_sendAddress3;
}
/*
* this method initializes tf_sendPostcode
* @return javax.swing.JTextField
*/
private JTextField getTf_sendPostcode() {
if(tf_sendPostcode == null) {
tf_sendPostcode = new JTextField();
tf_sendPostcode.setBounds(new Rectangle(366,256,109,22));
}
return tf_sendPostcode;
}
/*
* this method initializes tf_receiveName
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveName() {
if(tf_receiveName == null) {
tf_receiveName = new JTextField();
tf_receiveName.setBounds(new Rectangle(151,311,142,22));
}
return tf_receiveName;
}
/*
* this method initializes tf_receiveTelephone
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveTelephone() {
if(tf_receiveTelephone == null) {
tf_receiveTelephone = new JTextField();
tf_receiveTelephone.setBounds(new Rectangle(349,312,126,22));
}
return tf_receiveTelephone;
}
/*
* this method initializes tf_receiveCompany
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveCompany() {
if(tf_receiveCompany == null) {
tf_receiveCompany = new JTextField();
tf_receiveCompany.setBounds(new Rectangle(150,339,325,22));
}
return tf_receiveCompany;
}
/*
* this initializes tf_receiveAddress1
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress1() {
if(tf_receiveAddress1 == null) {
tf_receiveAddress1 = new JTextField();
tf_receiveAddress1.setBounds(new Rectangle(115,377,363,22));
}
return tf_receiveAddress1;
}
/*
* this initializes tf_receiveAddress2
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress2() {
if(tf_receiveAddress2 == null) {
tf_receiveAddress2 = new JTextField();
tf_receiveAddress2.setBounds(new Rectangle(115,404,362,22));
}
return tf_receiveAddress2;
}
/*
* this initializes tf_receiveAddress3
* @return javax.swing.JTextField
*/
private JTextField getTf_receiveAddress3() {
if(tf_receiveAddress3 == null) {
tf_receiveAddress3 = new JTextField();
tf_receiveAddress3.setBounds(new Rectangle(116,430,362,22));
}
return tf_receiveAddress3;
}
/*
* this method initializes tf_receivePostcode
* @return javax.swing.JTextField
*/
private JTextField getTf_receivePostcode() {
if(tf_receivePostcode == null) {
tf_receivePostcode = new JTextField();
tf_receivePostcode.setBounds(new Rectangle(366,456,112,22));
}
return tf_receivePostcode;
}
}
UpdateUserPasswordFrame.java
package com.zzk.frame;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import com.zzk.dao.UserDao;
public class UpdateUserPasswordFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JPasswordField pf_oldPwd = null;
private JPasswordField pf_newPwd = null;
private JPasswordField pf_okNewPwd = null;
private JButton btn_update = null;
private JButton btn_return = null;
/*
* this method initializes pf_oldPwd
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_oldPwd() {
if(pf_oldPwd == null) {
pf_oldPwd = new JPasswordField();
pf_oldPwd.setBounds(new Rectangle(93,21,185,22));
pf_oldPwd.setEchoChar('*');
pf_oldPwd.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_newPwd.requestFocus();
}
});
}
return pf_oldPwd;
}
/*
* this method initializes pf_newPwd
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_newPwd() {
if(pf_newPwd == null) {
pf_newPwd = new JPasswordField();
pf_newPwd.setBounds(new Rectangle(94,54,182,22));
pf_newPwd.setEchoChar('*');
pf_newPwd.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_okNewPwd.requestFocus();
}
});
}
return pf_newPwd;
}
/*
* this method initializes pf_okNewPwd
* @return javax.swing.JPasswordField
*/
private JPasswordField getPf_okNewPwd() {
if(pf_okNewPwd == null) {
pf_okNewPwd = new JPasswordField();
pf_okNewPwd.setBounds(new Rectangle(94,90,182,22));
pf_okNewPwd.setEchoChar('*');
pf_okNewPwd.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_okNewPwd.requestFocus();
/*
String oldPwd = new String(pf_oldPwd.getPassword());
String newPwd = new String(pf_newPwd.getPassword());
String okPwd = new String (pf_okNewPwd.getPassword());
UserDao.updateUser(oldPwd, newPwd, okPwd);
*/
}
});
}
return pf_okNewPwd;
}
/*
* this method initializes btn_update
* @return javax.swing.JButton
*/
private JButton getBtn_update() {
if(btn_update == null) {
btn_update = new JButton();
btn_update.setBounds(new Rectangle(40,123,75,27));
btn_update.setText("修 改");
btn_update.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
String oldPwd = new String(pf_oldPwd.getPassword());
String newPwd = new String(pf_newPwd.getPassword());
String okPwd = new String (pf_okNewPwd.getPassword());
UserDao.updateUser(oldPwd, newPwd, okPwd);
}
});
}
return btn_update;
}
/*
* this method initializes btn_return
* @return javax.swing.JButton
*/
private JButton getBtn_return() {
if(btn_return == null) {
btn_return = new JButton();
btn_return.setBounds(new Rectangle(162,124,82,26));
btn_return.setText("返 回");
btn_return.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
dispose();
}
});
}
return btn_return;
}
/*
* this is the default constructor
*/
public UpdateUserPasswordFrame() {
super();
initialize();
}
/*
* this method initializes this
* @return void
*/
private void initialize() {
this.setSize(317,205);
this.setContentPane(getJContentPane());
this.setTitle("修改用户密码");
}
/*
* this method initializes jContentPane
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if(jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(19,86,73,27));
jLabel2.setText("确认密码:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(20,52,70,27));
jLabel1.setText("新密码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(18,18,71,27));
jLabel.setText("原密码:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,null);
jContentPane.add(jLabel1,null);
jContentPane.add(jLabel2,null);
jContentPane.add(getPf_oldPwd(),null);
jContentPane.add(getPf_newPwd(),null);
jContentPane.add(getPf_okNewPwd(),null);
jContentPane.add(getBtn_update(),null);
jContentPane.add(getBtn_return(),null);
}
return jContentPane;
}
}
com.zzk.panel
BackgroundPanel.java
package com.zzk.panel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JPanel;
public class BackgroundPanel extends JPanel {
private Image image;
public BackgroundPanel(Image image) {
super();
this.image = image;
initialize();
}
protected void paintComponent(Graphics g) {
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g;
if(image != null) {
int width = getWidth();
int height = getHeight();
g2.drawImage(image,0,0,width,height,this);
}
}
private void initialize() {
this.setSize(300, 200);
}
}
com.zzk.tool
SaveUserStateTool.java
package com.zzk.tool;
public class SaveUserStateTool {
private static String username = null;
private static String password = null;
public static String getUsername() {
return username;
}
public static void setUsername(String username) {
SaveUserStateTool.username = username;
}
public static String getPassword() {
return password;
}
public static void setPassword(String password) {
SaveUserStateTool.password = password;
}
}
成果图片:
登录窗口,主窗口,添加快递窗口,修改快递窗口,添加用户窗口,修改密码窗口