这是学校的实训项目,但是我太菜了,写不出快递单查询。
要求快递单查询可以根据ID或者姓名,甚至是名字开头的字查询出来。
可以根据模糊的关键字查询,比如输入广东省,显示含有广东省的地址的快递单信息。
还请大神们教一下我!
还有留下一些学习java的方法,因为我觉得平时写玩具式代码还行的,但是要整合在一起就蒙圈了。
实训要求如下:
遇到的问题:
- 不会写查询快递单
- 打印功能虽然能打印,但是打印出来缺少省份和城市
- 添加快递单的时候确实录入了省份城市等信息
- 口令安全安全保护还没有添加
贴一下代码
package com.ebmis.frame;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JFrame;
import com.ebmis.bean.User;
import com.ebmis.dao.UserDao;
import com.ebmis.panel.BackgroundPanel;
import java.net.URL;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
/**
* 登陆面板
*
* 系统登录
*
*/
public class LoginFrame extends JFrame {
private static final long serialVersionUID = 1L;
//添加组件容器
private JPanel jContentPane = null;
private URL url = null;
// 声明图像对象
private Image image = null;
// jPanel默认是FlowLayout
//声明自定义背景面板对象
private BackgroundPanel jPanel = null;
// 总标签???
private JLabel jLabel = null;
// 密码标签
private JLabel passwordLabel = 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) {
// 创建密码标签
passwordLabel = new JLabel();
// 密码标签的属性设置
passwordLabel.setBounds(new Rectangle(221, 176, 63, 18));
passwordLabel.setText("密 码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(220, 141, 63, 18));
jLabel.setText("用 户:");
// 获得图片的URL
url = UpdateExpressFrame.class.getResource("/image/登录.jpg");
// 创建图像对象
image = new ImageIcon(url).getImage();
jPanel = new BackgroundPanel(image);
// 设置布局
jPanel.setLayout(null);
//把组件添加到容器
jPanel.add(jLabel, null);
jPanel.add(passwordLabel, 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;
}
/**
* 获取用户名
*/
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() {
public void actionPerformed(java.awt.event.ActionEvent e) {
pf_password.requestFocus();
}
});
}
return tf_username;
}
/**
* 获取用户密码,用户登录
*/
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() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// 用户登陆触发方法
userLogin();
}
});
}
return pf_password;
}
/**
* 登录按钮,用户登录
*/
private JButton getBtn_login() {
if (btn_login == null) {
btn_login = new JButton();
btn_login.setBounds(new Rectangle(221, 211, 56, 22));
btn_login.setRolloverIcon(new ImageIcon(getClass().getResource(
"/image/dl.jpg")));
btn_login.setIcon(new ImageIcon(getClass().getResource(
"/image/dl01.jpg")));
btn_login.setMargin(new Insets(0, 0, 0, 0));
btn_login.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// 用户登陆触发方法
userLogin();
}
});
}
return btn_login;
}
/**
* 用户登陆触发方法
*/
private void userLogin() {
String username = tf_username.getText().trim();
String password = new String(pf_password.getPassword());
//创建user对象
User user = new User();
//获取用户名
user.setName(username);
//获取密码
user.setPwd(password);
//如果登录成功,则创建MainFrame对象
//此处调用了
if (UserDao.userLogin(user)) {
//创建MainFrame对象
MainFrame thisClass = new MainFrame();
//默认窗体关闭
thisClass.setDefaultCloseOperation(JFrame.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();
}
}
/**
*
* 初始化重设按钮
* This method initializes btn_reset
*
* @return javax.swing.JButton
*/
private JButton getBtn_reset() {
if (btn_reset == null) {
//创建按钮
btn_reset = new JButton();
//设置按钮属性
btn_reset.setBounds(new Rectangle(299, 211, 55, 23));
//???
btn_reset.setRolloverIcon(new ImageIcon(getClass().getResource(
"/image/cz.jpg")));
btn_reset.setIcon(new ImageIcon(getClass().getResource(
"/image/cz01.jpg")));
btn_reset.setMargin(new Insets(0, 0, 0, 0));
//设置监听事件
btn_reset.addActionListener(new java.awt.event.ActionListener() {
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
*/
private JButton getBtn_exit() {
if (btn_exit == null) {
btn_exit = new JButton();
btn_exit.setBounds(new Rectangle(374, 211, 53, 22));
btn_exit.setRolloverIcon(new ImageIcon(getClass().getResource(
"/image/tc.jpg")));
btn_exit.setIcon(new ImageIcon(getClass().getResource(
"/image/tc01.jpg")));
btn_exit.setMargin(new Insets(0, 0, 0, 0));
btn_exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//退出JVM
System.exit(0);
}
});
}
return btn_exit;
}
/**
* main方法
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//线程,实现Runnable()接口
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//创建LoginFrame的对象且设置为默认关闭
LoginFrame thisClass = new LoginFrame();
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);
}
});
}
/**
* LoginFrame的构造函数
* This is the default constructor
*/
public LoginFrame() {
super();
//调用initialize();方法
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;
}
} // @jve:decl-index=0:visual-constraint="10,10"
package com.ebmis.frame;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.ebmis.panel.BackgroundPanel;
import com.ebmis.tool.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
public class MainFrame 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 JMenuBar winMenuBar = null;
private JMenu mnuExpressMan = null;// 快递单管理
private JMenu mnuPrintMan = null;// 打印管理菜单
private JMenu mnuUserMan = null;// 打印管理菜单
private JMenu mnuSys = null;// 系统菜单
private JMenuItem miPrint = null;// 打印菜单
private JMenuItem miPwdEdit = null;// 修改密码菜单
private JMenuItem miExitSys = null;// 退出菜单
private JMenuItem miUserNew = null;// 添加用户菜单
private JMenuItem miExpressNew = null;// 添加快递单
private JMenuItem miExpressEdit = null;// 修改快递单
private JMenuItem miExpressQuery = null;// 查询快递单
/**
* 主窗体构造方法
*/
public MainFrame() {
super();
initialize();
}
/**
* 窗体初始化
*/
private void initialize() {
this.setSize(1017, 584);// 设置大小
this.setJMenuBar(getMainWinMenu());// 设置菜单栏
this.setTitle("快递单信息管理系统(当前用户:"+EbmisTool.getUsername()+")");// 标题
this.setContentPane(getJContentPane());// 设置主容器
}
/**
* 获取窗体主容器面板
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.CENTER);
}
return jContentPane;
}
/**
* 背景面板
*/
private BackgroundPanel getJPanel() {
if (jPanel == null) {
url = MainFrame.class.getResource("/image/主界面.jpg"); // 获得图片的URL
image = new ImageIcon(url).getImage(); // 创建图像对象
jPanel = new BackgroundPanel(image);
jPanel.setLayout(null);
}
return jPanel;
}
/**
* 获取菜单栏
*/
private JMenuBar getMainWinMenu() {
if (winMenuBar == null) {
winMenuBar = new JMenuBar();
winMenuBar.add(getMenuTop4Sys());
winMenuBar.add(getMenuTop4UserMan());
winMenuBar.add(getMenuTop4ExpressMan());
winMenuBar.add(getMenuTop4PrintMan());
}
return winMenuBar;
}
/**
* 获取“快递单管理”菜单
*/
private JMenu getMenuTop4ExpressMan() {
if (mnuExpressMan == null) {
mnuExpressMan = new JMenu();
mnuExpressMan.setText("快递单管理");
mnuExpressMan.add(getMenuItem4ExpressNew());
mnuExpressMan.add(getMenuItem4ExpressEdit());
mnuExpressMan.add(getMenuItem4ExpressQuery());
}
return mnuExpressMan;
}
/**
* 获取“添加快递单”菜单
*/
private JMenuItem getMenuItem4ExpressNew() {
if (miExpressNew == null) {
miExpressNew = new JMenuItem();
miExpressNew.setText("新增");
miExpressNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
AddExpressFrame thisClass = new AddExpressFrame();
thisClass.setDefaultCloseOperation(JFrame.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 miExpressNew;
}
/**
* 获取“修改快递单”菜单
*/
private JMenuItem getMenuItem4ExpressEdit() {
if (miExpressEdit == null) {
miExpressEdit = new JMenuItem();
miExpressEdit.setText("修改");
miExpressEdit
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
UpdateExpressFrame thisClass = new UpdateExpressFrame();
thisClass.setDefaultCloseOperation(JFrame.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 miExpressEdit;
}
/**
* 获取“查询快递单”菜单
*/
private JMenuItem getMenuItem4ExpressQuery() {
if (miExpressQuery == null) {
miExpressQuery = new JMenuItem();
miExpressQuery.setText("查询");
miExpressQuery
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//TODO
}
});
}
return miExpressQuery;
}
/**
* 获取“打印管理”菜单
*/
private JMenu getMenuTop4PrintMan() {
if (mnuPrintMan == null) {
mnuPrintMan = new JMenu();
mnuPrintMan.setText("打印");
mnuPrintMan.add(getMenuItem4Print());
}
return mnuPrintMan;
}
/**
* 获取“用户管理”菜单
*/
private JMenu getMenuTop4UserMan() {
if (mnuUserMan == null) {
mnuUserMan = new JMenu();
mnuUserMan.setText("用户管理");
mnuUserMan.add(getMenuItem4AddUser());
mnuUserMan.add(getMenuItem4PwdEdit());
}
return mnuUserMan;
}
/**
* 获取“系统”菜单
*/
private JMenu getMenuTop4Sys() {
if (mnuSys == null) {
mnuSys = new JMenu();
mnuSys.setText("系统");
mnuSys.add(getMenuItem4SysExit());
}
return mnuSys;
}
/**
* 获取“打印快递单”菜单
*/
private JMenuItem getMenuItem4Print() {
if (miPrint == null) {
miPrint = new JMenuItem();
miPrint.setText("打印快递单");
miPrint.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
PrintExpressFrame thisClass = new PrintExpressFrame();
thisClass.setDefaultCloseOperation(JFrame.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 miPrint;
}
/**
* 获取“修改用户密码”菜单
*/
private JMenuItem getMenuItem4PwdEdit() {
if (miPwdEdit == null) {
miPwdEdit = new JMenuItem();
miPwdEdit.setText("修改密码");
miPwdEdit
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
UpdatePasswordFrame thisClass = new UpdatePasswordFrame();
thisClass
.setDefaultCloseOperation(JFrame.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 miPwdEdit;
}
/**
* 获取“退出系统”菜单
*/
private JMenuItem getMenuItem4SysExit() {
if (miExitSys == null) {
miExitSys = new JMenuItem();
miExitSys.setText("退出系统");
miExitSys.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return miExitSys;
}
/**
* 获取“添加用户”菜单
*/
private JMenuItem getMenuItem4AddUser() {
if (miUserNew == null) {
miUserNew = new JMenuItem();
miUserNew.setText("新增");
miUserNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
AddUserFrame thisClass = new AddUserFrame();
thisClass.setDefaultCloseOperation(JFrame.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 miUserNew;
}
}
package com.ebmis.frame;
import com.ebmis.tool.*;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.ebmis.bean.ExpressMessage;
import com.ebmis.dao.ExpressMessageDao;
import com.ebmis.panel.BackgroundPanel;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class AddExpressFrame 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 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() {
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);