1、 1.数据库存储入住人信息 2.数据库登陆账号密码4.公共类设计(1)公共类用于加载数据库驱动package xg。dao;import java。sql.Connection;sql.DriverManager;import javax.swing.JOptionPane;public class DAO SuppressWarnings(unused”) private static DAO dao = new DAO(); /* 构造方法,加载数据库驱动 / public DAO() try Class。forName(net.sourceforge。jtds。jdbc。Driver);
2、 catch (ClassNotFoundException e) JOptionPane.showMessageDialog(null, 数据库驱动加载失败,请将JTDS驱动配置到构建路径中.n” + e.getMessage(); / * 获得数据库连接的方法 return Connection public static Connection getConn() Connection conn = null; String url = jdbc:jtds:sqlserver:/localhost:1433/XG”; / 数据库XG路径 String username = sa”; / 数
3、据库的用户名 String password = 123456”; / 数据库密码 conn = DriverManager.getConnection(url, username, password); / 建立连接 return conn; catch (Exception e) JOptionPane.showMessageDialog(null, ”数据库连接失败。n请检查数据库用户名和密码是否正确。” + e。getMessage(); return null; 5.程序主要系统开发(1)系统登录界面登录系统在绘制背景前先获取该图片用getImage()方法获得image类型的对象,
4、然后获取ImagIcon类型对象,用该构造方法传递URL参数。主要函数超累构造方法:调用父类方法,绘制图像:与数据库连接判断函数:实现登陆功能:(主要函数) private JPanel getJPanel() if (jPanel = null) jLabel1 = new JLabel(); jLabel1.setBounds(new Rectangle(221, 176, 63, 18); jLabel1。setText(密 码:”);setForeground(Color。WHITE); jLabel = new JLabel(); jLabel.setBounds(new Recta
5、ngle(220, 141, 63, 18); jLabel.setText(”用 户: jLabel。setForeground(Color.WHITE); url = UpdateFrame。class.getResource(”/image/酒店登陆背景。jpg / 获得图片的URL image = new ImageIcon(url)。getImage(); / 创建图像对象 jPanel = new BackgroundPanel(image); jPanel。setLayout(null); jPanel.add(jLabel, null); jPanel.add(jLabel1,
6、 null);add(getTf_username(), null); jPanel.add(getPf_password(), null);add(getBtn_login(), null);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(
7、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;6.系统主界面主要函数代码:等其他看eclipse中的函数。7.登记入住界面/查看界面实现过程:登记入住界面用于酒店登记住户该窗体用到6个文本框和3个命令按钮.在sq
8、ldao中可以进行判断输入的数据是否符合要求或者是否有信息没有填写。package xg.frame;import java.awt。BorderLayout;FlowLayout;/import java。awt。Font;awt.Image;import java.awt.Rectangle;net。URL;import javax.swing。ImageIcon;JButton;JFrame;import javax.swing.JPanel;import javax.swing.JTextField;import xg.bean.S;import xg。dao。SQLDao;panel
9、.BackgroundPanel;public class AEFrame 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_A1 = null; private
10、 JTextField tf_A2 = null; private JTextField tf_sendCompany = null; private JTextField tf_timE1 = null; private JTextField tf_timE2 = null; private JTextField tf_timE3 = null; private JPanel jPanel1 = null; private JButton btn_clear = null; private JButton btn_save = null; private JButton btn_return
11、 = null; private JPanel getJPanel1() if (jPanel1 = null) jPanel1 = new JPanel(); jPanel1。setLayout(new FlowLayout(); jPanel1.add(getBtn_clear(), null); jPanel1.add(getBtn_save(), null);add(getBtn_return(), null); return jPanel1; private JButton getBtn_clear() if (btn_clear = null) btn_clear = new JB
12、utton(); btn_clear。清 空”); btn_clear.addActionListener(new java。event.ActionListener() Override public void actionPerformed(java.awt.event。ActionEvent e) tf_A1。setText(”姓名: tf_A2.setText(房间类型(A/B/C):); tf_sendCompany.setText(”身份证: tf_timE1.setText(”联系电话: tf_timE2。入住时间(年/月/日):”); tf_timE3.setText(退房日期
13、(年/月/日):requestFocus(); ); return btn_clear; private JButton getBtn_save() if (btn_save = null) btn_save = new JButton(); btn_save。保 存”);event。ActionListener() StringBuffer buffer = new StringBuffer(); S m = new S(); m.setA1(tf_A1.getText()。trim(); m.setA2(tf_A2。getText().trim(); m.setA3(tf_sendComp
14、any。getText()。 buffer.append(tf_A1.getX() + ,” + tf_A1.getY() + /”); buffer.append(tf_A2.getX() + ”, + tf_A2.getY() + ”/ buffer.append(tf_sendCompany.getX() + ”, + tf_sendCompany。getY() + ”/”); buffer。append(tf_timE1.getX() + ,” + tf_timE1。getY() + /append(tf_timE2.getX() + ”,” + tf_timE2。getY() + ”
15、/append(tf_timE3.getX() + ,” + tf_timE3。 m.setControlPosition(new String(buffer); m.setExpressSize(jPanel。getWidth() + , + jPanel。getHeight(); SQLDao.insertExpress(m); return btn_save; private JButton getBtn_return() if (btn_return = null) btn_return = new JButton(); btn_return。setText(”返 回”); dispo
16、se(); return btn_return; public AEFrame() super(); initialize(); private void initialize() this.setSize(617, 413); this。setTitle(登记入住界面”); this.setContentPane(getJContentPane(); private JPanel getJContentPane() if (jContentPane = null) jContentPane = new JPanel(); jContentPane.setLayout(new BorderLa
17、yout(); jContentPane.add(getJPanel(), BorderLayout.CENTER); jContentPane.add(getJPanel1(), BorderLayout。SOUTH); return jContentPane; private BackgroundPanel getJPanel() url = AEFrame。class.getResource(/image/登记界面.jpgsetLayout(null); jPanel.add(getTf_A1(), null);add(getTf_A2(), null); jPanel.add(getT
18、f_sendCompany(), null); jPanel.add(getTf_timE1(), null); jPanel.add(getTf_timE2(), null); jPanel.add(getTf_timE3(), null); return jPanel; private JTextField getTf_A1() if (tf_A1 = null) tf_A1 = new JTextField(”姓名: tf_A1.setBounds(new Rectangle(114, 114, 139, 22); return tf_A1; private JTextField get
19、Tf_A2() if (tf_A2 = null) tf_A2 = new JTextField(); tf_A2。setBounds(new Rectangle(347, 114, 131, 22); return tf_A2; private JTextField getTf_sendCompany() if (tf_sendCompany = null) tf_sendCompany = new JTextField(”身份证: tf_sendCompany。setBounds(new Rectangle(114, 141, 362, 22); return tf_sendCompany
20、; private JTextField getTf_timE1() if (tf_timE1 = null) tf_timE1 = new JTextField(联系电话: tf_timE1.setBounds(new Rectangle(114, 179, 362, 22); return tf_timE1; private JTextField getTf_timE2() if (tf_timE2 = null) tf_timE2 = new JTextField(入住时间(年/月/日): tf_timE2.setBounds(new Rectangle(114, 205, 362, 2
21、2); return tf_timE2; private JTextField getTf_timE3() if (tf_timE3 = null) tf_timE3 = new JTextField(退房日期(年/月/日): tf_timE3。setBounds(new Rectangle(114, 230, 362, 22); return tf_timE3;8.修改登记入住界面修改入住界面多了一个可以修改的按钮,修改后的数据可以保存到数据库中并且显示 private JButton getBtn_update() if (btn_update = null) btn_update = n
22、ew JButton(); btn_update.setText(修 改 btn_update.addActionListener(new java。 m。setId(id);setA1(tf_A1。setA2(tf_A2。trim(); m.setA3(tf_sendCompany.getText()。settimE(tf_timE1.getText().trim() + ” + tf_timE2。trim() + ” + tf_timE3.getText().trim();append(tf_A1。getX() + ,” + tf_A1。 buffer.append(tf_A2。,” +
23、tf_A2.getY() + ”/ buffer.append(tf_sendCompany.getX() + , + tf_sendCompany.getY() + ”/”); buffer.append(tf_timE1.getX() + ,” + tf_timE1.getY() + ”/ buffer.append(tf_timE2。,” + tf_timE2.getY() + append(tf_timE3.getX() + ”, + tf_timE3。 SQLDao。updateExpress(m); queryResultVector = SQLDao。queryAllExpres
24、s(); if (queryResultVector != null) m = queryResultVector。get(queryRow); ); return btn_update;数据库中修改连接代码 public static void updateExpress(S m) Connection conn = null; PreparedStatement ps = null; conn = DAO。getConn(); ps = conn 。prepareStatement(update tb_receiveSendMessage set A1=?,A2=?,A3=?,timE=?,ControlPosition=?,expressSize=? where id = ? ps.setString(1, m。getA1(); ps.setString(2, m.getA2(); ps.setString(3, m.getA3(); ps。setString(4, m.gettimE(); ps.setString(
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1