一、 使用方法:
在使用前,需要到druid.properties
配置文件中,修改自己對應于自己數據庫的屬性;如用戶名,密碼等
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql:///hotel?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
username=root
password=123456
# 初始化連接數量
initialSize=5
# 最大連接數
maxActive=10
# 最大等待時間
maxWait=3000
注意:如果是保持數據庫連接異常,則說明數據庫和jar包版本匹配了,注意升級數據庫jar包版本;
二、項目介紹
- 本項目主要是基于Swing框架搭建的java桌面應用程序 在項目中主要實現的功能有:
1.開始界面
- 開始界面為動態代碼雨的歡迎效果
2.注冊界面
-
注冊界面。實現了驗證碼的生成和驗證,以及出生日期的日歷控件化的選擇,當用戶注冊成功后,用戶名密碼就會通過方法傳到登錄界面從而避免了用戶第二次填賬號密碼的麻煩
3.分角色登錄
-
登錄主要分為管理員登錄和用戶登錄,管理員登錄后有
- 客房管理功能:這個功能主要實現了對房間的增刪改查,以及查看對應房間的評論等;涉及到了多對多的查詢
4.用戶管理
- 用戶管理功能:主要的增刪改查操作,點擊對應的用戶右邊小框框展示用戶的頭像
5.訂單管理
- 訂單管理功能:在這里會展示用戶的全部訂單,通過多對多的查詢展示用戶的訂房信息等;已經對用戶的一些信息進行統計;主要用到了ifreechart 框架進行繪制表格
6.客房服務
- 客房服務功能:就是給房間添加一些新的設備以及多張配圖,方便用戶瀏覽
7.歷史記錄
- 歷史記錄:主要記錄用戶的訂房退房記錄,實現這個功能主要用到mysql的觸發器,通過觸發器,沒刪除一個訂單,就將對于的訂單保存到歷史記錄表里邊;最后導出表格,而我導出的表格用csv文件逗號陣列,比較方便生成
8.管理員登錄
-
管理員管理,主要是設置權限的1位超級管理員0 為普通管理員

-
在退出前會有監聽事件,會詢問用戶是否最小化托盤,如果最小化托盤則項目已經在運行中
-
在登錄前,由于想模仿QQ登錄功能輸入對應的賬號顯示不同的頭像,最后添加了鍵盤監聽功能和數據庫查詢,所以剛開始會有點卡
-
9.查看房間
-
用戶登錄功能
-
用戶登錄后,可以查看房間和其各種資料;
-
10.點評房間
-
用戶也可以點評房間
11.充值界面
-
用戶可以對客房進行預訂,如果金額不足之前則需要用戶進行充值
- 而充值界面需要用戶點擊我的頭像那里進入個人信息頁面
-
用戶個人信息還有評論記錄都可以在個人信息這里修改刪除等
三、文件夾目錄說明
image 主要用于保存項目中用到的圖片文件的
lib 主要用于保存用項目中用到jar包
sql 整個項目運行的數據和數據庫表
src 全部源碼com.ludashen.control 主要保存各種自定義的控件的com.ludashen.dao 數據庫交互代碼com.ludashen.frame 用戶交互界面代碼com.ludashen.hothl 模型對象類com.ludashen.panel 面板容器
resource 資源文件,圖片等
druid.properties 數據庫配置文件
四、 代碼
1.runFrame
package com.ludashen.frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;public class RunFrame extends JDialog implements ActionListener {private int gi=0;private Random random = new Random();private Dimension screenSize;private JPanel graphicsPanel;private final static int gap = 20;//存放雨點頂部的位置信息(marginTop)private int[] posArr;//行數private int lines;//列數private int columns;public RunFrame() {initComponents();}private void initComponents() {setLayout(new BorderLayout());graphicsPanel = new GraphicsPanel();add(graphicsPanel, BorderLayout.CENTER);this.setUndecorated(true);setSize(500,400);setLocationRelativeTo(null);this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);screenSize = Toolkit.getDefaultToolkit().getScreenSize();lines = screenSize.height / gap;columns = screenSize.width / gap;posArr = new int[columns + 1];random = new Random();for (int i = 0; i < posArr.length; i++) {posArr[i] = random.nextInt(lines);}new Timer(120, this).start();}private int getChr() {return random.nextInt(10);}//定時器的@Overridepublic void actionPerformed(ActionEvent e) {graphicsPanel.repaint();}private class GraphicsPanel extends JPanel {@Overridepublic void paint(Graphics g) {Graphics2D g2d = (Graphics2D) g;g2d.setFont(getFont().deriveFont(Font.BOLD));g2d.setColor(Color.BLACK);g2d.fillRect(0, 0, screenSize.width, screenSize.height);//當前列int currentColumn = 0;for (int x = 0; x < screenSize.width; x += gap) {int endPos = posArr[currentColumn];g2d.setColor(Color.CYAN);g2d.drawString(String.valueOf(getChr()), x, endPos * gap);int cg = 0;for (int j = endPos - 15; j < endPos; j++) {//顏色漸變cg += 20;if (cg > 255) {cg = 255;}g2d.setColor(new Color(0, cg, 0));g2d.drawString(String.valueOf(getChr()), x, j * gap);}//每放完一幀,當前列上雨點的位置隨機下移1~5行posArr[currentColumn] += random.nextInt(5);//當雨點位置超過屏幕高度時,重新產生一個隨機位置if (posArr[currentColumn] * gap > getHeight()) {posArr[currentColumn] = random.nextInt(lines);}currentColumn++;}if(gi>6){g2d.setFont(new Font("italicc",3,25));g2d.setColor(Color.WHITE);g2d.drawString("歡迎使用酒店管理系統", getWidth()/2-100, getHeight()/2);}if(gi++>25){dispose();new LoginFrame().setVisible(true);}}}public static void main(String[] args) {new RunFrame();}
}
2.UserFrame
package com.ludashen.frame;import com.ludashen.control.*;import com.ludashen.dao.CommentDao;
import com.ludashen.dao.HouseDao;
import com.ludashen.dao.RoomInfoDao;
import com.ludashen.dao.UserDao;
import com.ludashen.hothl.Comment;
import com.ludashen.hothl.House;
import com.ludashen.hothl.RoomInfo;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.ArrayList;
import java.util.List;
import java.util.Map;public class UserFrame extends JFrame {private Map<String, Object> userInfo;//保存用戶信息的private JMenuBar menuBar;private JLabel title,img; //選中列表顯示房子標題和圖片private JTextPane tDetails; //客房詳情private JTextPane tComment; //顧客點評private List<House> house;private int hid; //用于記錄房子id的private String detail; //記錄房子詳情的private JList buddyList; //列表信息private int choose; //獲取當前選擇的列private List<String> image=new ArrayList<>();//用于放當前房間的片private int index;//記錄當前放到那張照片了public UserFrame(String uid){//構造函數根據登錄id查找用戶信息super("酒店管理系統");try {userInfo= UserDao.users(uid);}catch (Exception e){JOptionPane.showMessageDialog(null,"沒有這個用戶請重新登錄");System.exit(0);}setTitle("酒店系統----"+userInfo.get("uName")+"在線");init();}private void init() {setResizable(false);//設置標題圖標setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resource/log.png")));title= new JLabel();img=new JLabel();tDetails=new JTextPane();tComment=new JTextPane();tComment.setEnabled(false);tDetails.setEnabled(false);tDetails.setBackground(new Color(0x134FAE));addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {super.windowClosing(e);if (JOptionPane.showConfirmDialog(null, "是否最小化托盤") != 0) {System.exit(0);}}});tDetails.setContentType("text/html");tComment.setContentType("text/html");title.setFont(new Font("",1,30));topBar();Tool.SystemTrayInitial(this);this.add(mainPanel());this.setSize(900,750);this.setLocationRelativeTo(null);}private JPanel mainPanel(){JPanel p=new JPanel(null);JPanel panel = new JPanel();tDetails.setOpaque(false);RScrollPane details=new RScrollPane(tDetails,"/resource/bg1.jpg");panel.setLayout(new BorderLayout());JPanel p2=new JPanel(new BorderLayout());JTextField field=new JTextField(50);field.setSize(500,30);RButton send=new RButton("發送");p2.add(field,BorderLayout.WEST);p2.add(send,BorderLayout.EAST);panel.add(p2, BorderLayout.SOUTH);tComment.setOpaque(false);RScrollPane comment=new RScrollPane(tComment,"/resource/bg1.jpg");panel.add(comment, BorderLayout.CENTER);JTabbedPane jTabbedPane =Tool.jTabbedPane(235,450,p,640,215);jTabbedPane.setTabPlacement(1);Tool.Tabp(jTabbedPane,"酒店詳情", "/resource/tabp/applicatio.png",details, "詳情");Tool.Tabp(jTabbedPane,"點評列表", "/resource/tabp/Comment.png", panel, "列表");RButton ding=Tool.rButton(800,5,"預定",p,80);title.setBounds(240,5,260,45);img.setBounds(240,50,630,400);p.add(Tool.getFunButton(500, 10, "/resource/button/back1.png", "/resource/button/back2.png", e->{setBackImage();}));p.add(Tool.getFunButton(600, 10, "/resource/button/next1.png", "/resource/button/next2.png", e -> {setNetImage();}));RButton refresh=Tool.rButton(0,633,"刷新",p,235);send.addActionListener(e->{Comment comment1=new Comment((String) userInfo.get("uid"),String.valueOf(hid),field.getText());if(CommentDao.setCommentDao(comment1)) {tComment.setText(commentDao());JOptionPane.showMessageDialog(null,"評論成功!");field.setText("");}});ding.addActionListener(e ->{new YudingDialog(house.get(choose).getHid(),(String) userInfo.get("uid"),(Float) userInfo.get("money")).setVisible(true);});refresh.addActionListener(e -> {reRoom();});p.add(img);p.add(title);p.add(listRoom());p.add(refresh);return p;}private JScrollPane listRoom(){buddyList = new JList();buddyList.setOpaque(false);reRoom();if(house.size()!=0){img.setIcon(new ImageIcon((Image) new ImageIcon("image\\room\\"+house.get(0).gethImg()).getImage().getScaledInstance(630, 400,Image.SCALE_DEFAULT )));title.setText(house.get(0).gethName());image.add(house.get(0).gethImg());hid=house.get(0).getHid();detail= "<html><h2>詳情:"+house.get(0).gethDetails()+"</h2>"+roomInfo()+"</html>";tDetails.setText(detail);choose=0;}else {tDetails.setText("<h1>沒有空房間</h1>");}buddyList.addListSelectionListener(e -> {if(buddyList.getValueIsAdjusting())try {img.setIcon(new ImageIcon((Image) new ImageIcon("image\\room\\"+house.get(buddyList.getSelectedIndex()).gethImg()).getImage().getScaledInstance(630, 400,Image.SCALE_DEFAULT ))); //設置JLable的圖片image.clear();index=0;image.add(house.get(buddyList.getSelectedIndex()).gethImg());hid=house.get(buddyList.getSelectedIndex()).getHid();detail= "<html><h2>詳情:"+house.get(buddyList.getSelectedIndex()).gethDetails()+"</h2>"+roomInfo()+"</html>";title.setText(house.get(buddyList.getSelectedIndex()).gethName());tDetails.setText(detail);tComment.setText(commentDao());choose=buddyList.getSelectedIndex();for (RoomInfo imgs:RoomInfoDao.getRoomInfo(hid,3)){image.add(imgs.getFuntion());}}catch (Exception e1){buddyList.clearSelection();}});buddyList.setCellRenderer(new FriListCellRenderer());buddyList.setFont(new Font(Font.SERIF, Font.PLAIN, 18));buddyList.setPreferredSize(new Dimension(230, 72*house.size()));RScrollPane jp = new RScrollPane(buddyList,"");jp.setBounds(0,0,233,630);return jp;}private void setNetImage() {if(index==image.size()-1) {JOptionPane.showMessageDialog(null,"已經是最后一張了");return;}elseindex++;img.setIcon(new ImageIcon((Image) new ImageIcon("image\\room\\"+image.get(index)).getImage().getScaledInstance(630, 400,Image.SCALE_DEFAULT )));}private void setBackImage(){if(index==0) {JOptionPane.showMessageDialog(null,"已經是第一張了");return;}index--;img.setIcon(new ImageIcon((Image) new ImageIcon("image\\room\\"+image.get(index)).getImage().getScaledInstance(630, 400,Image.SCALE_DEFAULT )));}public void reRoom(){house= HouseDao.getHouser(2);HouseModel buddy = new HouseModel(house);buddyList.setModel(buddy);}private String roomInfo(){List<RoomInfo> roomInfo =RoomInfoDao.getRoomInfo(hid,1);StringBuffer str=new StringBuffer();for(RoomInfo info:roomInfo){str.append("<p>"+info.getName()+":");str.append(info.getFuntion()+"</p>");}return str.toString();}private String commentDao(){int a=0;List<Comment> comments= CommentDao.getRoomComment(String.valueOf(hid),1);StringBuffer str=new StringBuffer();str.append("<html>");for (Comment comment:comments){if(a%2==0) {str.append("<div style='background-color:#3333CC;'><span style='font-size: 20px'>");str.append(comment.getUid() + "</span><br>");str.append(comment.getComment() + "<br>" + comment.getDate());str.append("<br></div>");}else {str.append("<div style='background-color:#3300FF;'><span style='font-size: 20px'>");str.append(comment.getUid() + "</span><br>");str.append(comment.getComment() + "<br>" + comment.getDate());str.append("<br></div>");}a++;}if (comments.size()==0)str.append("占時沒有評論");str.append("</table></html>");return str.toString();}private void topBar() {menuBar = new JMenuBar();menuBar.setLayout(null);JButton head=new CircleButton(40,(String)userInfo.get("head"));head.setBounds(840, 0, 40, 40);head.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {super.mouseClicked(e);new UserInfoDialog(userInfo).setVisible(true);}});JMenu menu = new JMenu("酒店");menu.setBounds(0,0,80,30);JMenuItem zmenu = new JMenuItem("酒店簡介");zmenu.addActionListener(e->{IntroduceDialog introduceDialog = new IntroduceDialog();introduceDialog.setVisible(true);new Thread(introduceDialog).start();});menu.add(zmenu);menuBar.add(head);menuBar.add(menu);menuBar.setPreferredSize(new Dimension(300, 40));setJMenuBar(menuBar);}
}
3.loginFrame
package com.ludashen.frame;import com.ludashen.control.*;
import com.ludashen.dao.AdminDao;
import com.ludashen.dao.ContFile;
import com.ludashen.dao.UserDao;
import jdk.nashorn.internal.scripts.JO;import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.sql.SQLException;public class LoginFrame extends JFrame {private RPanel RP1;private RPanel RP2;private JPanel p;private JTextField userName;private JPasswordField password;private static Boolean isAdmin=false;private JLabel head;ContFile file=new ContFile();public LoginFrame(){super();init();}public static void setAdmin(Boolean b){isAdmin=b;}private void init(){setResizable(false);//設置圖片URL re = getClass().getResource("/resource/log.png");ImageIcon ico =new ImageIcon(re);setIconImage(Toolkit.getDefaultToolkit().getImage(re));//設置標題圖標this.setLayout(null);RP1=new RPanel("/resource/Lmain.png");RP2=new RPanel("/resource/login.png");RP1.setBounds(0,0,600,400);RP2.setBounds(0,400,600,100);RP2.setLayout(null);RP1.setLayout(null);Tool.jLabel(50,40,"賬號:",RP2);Tool.jLabel(280,40,"密碼:",RP2);userName= Tool.jTextField(100, 40, RP2,162);password=Tool.passwordField(330, 40, '*',RP2,159);head=Tool.jLabel(250,150,"",RP1,100,100);userName.addKeyListener(new KeyAdapter() {@Overridepublic void keyReleased(KeyEvent e) {super.keyReleased(e);head.setIcon(new ImageIcon((Image) new ImageIcon("image\\head\\" +UserDao.head(userName.getText())).getImage().getScaledInstance(100, 100,Image.SCALE_DEFAULT )));}});RButton LoginButton=Tool.rButton(500, 39,"登錄",RP2,80);JLabel register=Tool.jLabel(530, 69,"快速注冊",RP2);JLabel set=Tool.jLabel(480, 69, "設置",RP2);setChangColor(register, new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {super.mouseClicked(e);new Register().setVisible(true);dispose();}});setChangColor(set, new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {super.mouseClicked(e);new LoginSetDialog().setVisible(true);}});RP1.add(Tool.getFunButton(560, 5, "/resource/close2.png", "/resource/close1.png", e->{System.exit(0);}));RP1.add(Tool.getFunButton(520, 5, "/resource/min1.png", "/resource/min2.png", e -> {setExtendedState(JFrame.ICONIFIED);}));LoginButton.addActionListener(e -> {try {String pass = file.readFile("pass");String[] sp = pass.split("@");String name = userName.getText();String spass = new String(password.getPassword());if (!isAdmin) {if (UserDao.getUser(name, spass)) {if (sp[0].trim().equals("0")) {file.writeFile("pass", "0@" + name + "@" + spass);} else {file.writeFile("pass", "1");}new UserFrame(name).setVisible(true);dispose();} else {JOptionPane.showMessageDialog(null, "您現在正在登陸用戶系統,而用戶密碼或名字錯誤");}} else {if (AdminDao.getAdminLogin(name, spass)) {if (sp[0].trim().equals("0")) {file.writeFile("pass", "0@" + name + "@" + spass);} else {file.writeFile("pass", "1");}new AdminFrame(name).setVisible(true);dispose();} else {JOptionPane.showMessageDialog(null, "您現在正在登陸管理系統,用戶密碼或名字錯誤");}}}catch (Exception e1){
// new ContFile().writeFile("e.txt",e1.printStackTrace());JOptionPane.showMessageDialog(null,e1.getLocalizedMessage());}});pass();this.add(RP1);this.add(RP2);this.setUndecorated(true);//去掉標題欄this.setSize(600,500);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(3);}private void pass(){String pass=file.readFile("pass");String[] sp=pass.split("@");if(sp[0].trim().equals("0")&&sp.length>1){userName.setText(sp[1]);password.setText(sp[2]);head.setIcon(new ImageIcon((Image) new ImageIcon("image\\head\\" +sp[1]).getImage().getScaledInstance(100, 100,Image.SCALE_DEFAULT )));}}private void setChangColor(JLabel jLabel,MouseListener l){jLabel.addMouseListener(l);jLabel.addMouseListener(new MouseAdapter() {@Overridepublic void mouseEntered(MouseEvent e) {super.mouseEntered(e);jLabel.setForeground(Color.WHITE);}@Overridepublic void mouseExited(MouseEvent e) {super.mouseExited(e);jLabel.setForeground(Color.ORANGE);}});}public void setUser(String name,String pass){userName.setText(name);password.setText(pass);}}
五、聯系與交流
扣:969060742 運行視頻 完整程序資源 sql 程序資源