1、项目效果演示
DC00002基于java swing KTV点歌系统java GUI点歌管理系统Java GUI+MySQL点歌管理系统
2、项目功能描述
基于java swing+MySQL ktv点歌系统分为管理员和用户端
管理员端:
1、修改密码、退出系统
2、启用新房间、注销房间、房间信息维护
3、添加歌曲、歌曲信息维护、添加歌手、歌手信息维护
用户端:
1、检索点歌:歌星点歌、歌名点歌、拼音点歌、字数点歌
2、榜单点歌
3、已点歌曲:开始、原/伴奏、优先、切歌、删除、暂停、音量+、音量-
3、项目效果图(部分)
4、核心代码(部分)
4.1 登录窗口
package com.jakey.view;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.jakey.dao.AdminDao;
import com.jakey.dao.RoomDao;
import com.jakey.model.Admin;
import com.jakey.model.Room;
import com.jakey.util.DbUtil;
import com.jakey.util.StringUtil;
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
/**
*
* @author __USER__
*/
public class LogOnFrm extends javax.swing.JFrame {
DbUtil dbUtil = new DbUtil();
AdminDao adminDao = new AdminDao();
RoomDao roomDao = new RoomDao();
public static Admin currentAdmin;
public static Room currentRoom;
/** Creates new form LogOnFrm */
public LogOnFrm() {
//改变系统默认字体
// Font font = new Font("Dialog", Font.PLAIN, 12);
// java.util.Enumeration keys = UIManager.getDefaults().keys();
// while (keys.hasMoreElements()) {
// Object key = keys.nextElement();
// Object value = UIManager.get(key);
// if (value instanceof javax.swing.plaf.FontUIResource) {
// UIManager.put(key, font);
// }
// }
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
initComponents();
//设置Frame居中显示
this.setLocationRelativeTo(null);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTabbedPane3 = new javax.swing.JTabbedPane();
jTabbedPane2 = new javax.swing.JTabbedPane();
jTabbedPane6 = new javax.swing.JTabbedPane();
jLabel1 = new javax.swing.JLabel();
jtpLogIn = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
roomNoTxt = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
roomKeyTxt = new javax.swing.JPasswordField();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
adminNameTxt = new javax.swing.JTextField();
adminKeyTxt = new javax.swing.JPasswordField();
jb_logon = new javax.swing.JButton();
jb_reset = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u767b\u5f55");
setIconImage(new ImageIcon("./src/com/jakey/view/image/music.png").getImage());
jLabel1.setFont(new java.awt.Font("幼圆", 0, 36));
jLabel1
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\microphone.png")); // NOI18N
jLabel1.setText("KTV\u70b9\u6b4c\u7cfb\u7edf");
jLabel2
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\room.png")); // NOI18N
jLabel2.setText("\u623f\u95f4\u53f7\uff1a");
jLabel3
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\password.png")); // NOI18N
jLabel3.setText("\u5bc6 \u7801\uff1a");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout
.setHorizontalGroup(jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel2Layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
roomNoTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
156,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
roomKeyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
156,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(24, Short.MAX_VALUE)));
jPanel2Layout
.setVerticalGroup(jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel2Layout
.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
roomNoTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel2Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE,
15,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
roomKeyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(58, Short.MAX_VALUE)));
jtpLogIn.addTab("\u623f\u95f4\u767b\u5f55", jPanel2);
jLabel4
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\password.png")); // NOI18N
jLabel4.setText("\u5bc6 \u7801\uff1a");
jLabel5
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\admin.png")); // NOI18N
jLabel5.setText("\u7528\u6237\u540d\uff1a");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(
adminKeyTxt)
.addComponent(
adminNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
159,
Short.MAX_VALUE))
.addContainerGap(21, Short.MAX_VALUE)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(
adminNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(
adminKeyTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(54, 54, 54)));
jtpLogIn.addTab("\u7ba1\u7406\u5458\u767b\u5f55", jPanel1);
jb_logon
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\login.png")); // NOI18N
jb_logon.setText("\u767b\u5f55");
jb_logon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_logonActionPerformed(evt);
}
});
jb_logon.registerKeyboardAction(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_logonActionPerformed(evt);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
jb_reset
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\KtvSys\\src\\com\\jakey\\view\\image\\reset.png")); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addContainerGap(101, Short.MAX_VALUE)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
10,
10,
10)
.addComponent(
jtpLogIn,
javax.swing.GroupLayout.PREFERRED_SIZE,
267,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jb_logon)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jb_reset))
.addComponent(
jLabel1,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE,
294,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(84, 84, 84)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
62,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jtpLogIn,
javax.swing.GroupLayout.PREFERRED_SIZE,
169,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_logon)
.addComponent(jb_reset))
.addContainerGap(25, Short.MAX_VALUE)));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jb_logonActionPerformed(java.awt.event.ActionEvent evt) {
// String userName = userNameTxt.getText();
// String password = new String(passwordTxt.getPassword());
String adminName = adminNameTxt.getText();
String adminKey = new String(adminKeyTxt.getPassword());
String roomNo = roomNoTxt.getText();
String roomKey = new String(roomKeyTxt.getPassword());
int jtpIndex = jtpLogIn.getSelectedIndex();
if (jtpIndex == 0) {
if (StringUtil.isEmpty(roomNo)) {
JOptionPane.showMessageDialog(this, "房间号不能为空");
return;
}
if (StringUtil.isEmpty(roomKey)) {
JOptionPane.showMessageDialog(this, "密码不能为空");
return;
}
Room room = new Room(roomNo, roomKey);
Connection con = null;
try {
con = dbUtil.getCon();
currentRoom = roomDao.login(con, room);
if (currentRoom != null) {
if (!"已使用".equals(currentRoom.getRoomStatus())) {
JOptionPane.showMessageDialog(this, "房间未启用,不能登录!");
} else {
this.dispose();
new RoomFrm().setVisible(true);
}
} else {
JOptionPane.showMessageDialog(this, "房间号或密码错误");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(this, "登录失败");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
if (jtpIndex == 1) {
if (StringUtil.isEmpty(adminName)) {
JOptionPane.showMessageDialog(this, "用户名不能为空");
return;
}
if (StringUtil.isEmpty(adminKey)) {
JOptionPane.showMessageDialog(this, "密码不能为空");
return;
}
Admin admin = new Admin(adminName, adminKey);
Connection con = null;
try {
con = dbUtil.getCon();
currentAdmin = adminDao.login(con, admin);
if (currentAdmin != null) {
//如果要写成上面这种模式需要在新窗口的init方法中设定this.setVisible
// new AdminFrm();
this.dispose();
new AdminFrm().setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(this, "登录失败");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogOnFrm().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JPasswordField adminKeyTxt;
private javax.swing.JTextField adminNameTxt;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTabbedPane jTabbedPane2;
private javax.swing.JTabbedPane jTabbedPane3;
private javax.swing.JTabbedPane jTabbedPane6;
private javax.swing.JButton jb_logon;
private javax.swing.JButton jb_reset;
private javax.swing.JTabbedPane jtpLogIn;
private javax.swing.JPasswordField roomKeyTxt;
private javax.swing.JTextField roomNoTxt;
// End of variables declaration//GEN-END:variables
}
4.2 操作数据库
package com.jakey.util;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil {
private String dbUrl="jdbc:mysql://localhost:3305/db_ktv?useUnicode=true&characterEncoding=UTF8";
private String dbUserName="root";
private String dbPassword="root";
private String jdbcName="com.mysql.jdbc.Driver";
/**
* 获取数据库连接
* @return
* @throws Exception
*/
public Connection getCon() throws Exception{
Class.forName(jdbcName);
Connection con=DriverManager.getConnection(dbUrl,dbUserName, dbPassword);
return con;
}
/**
* 关闭数据库连接
* @param con
* @throws Exception
*/
public void closeCon(Connection con) throws Exception{
if(con!=null){
con.close();}
}
public static void main(String[] args) {
DbUtil dbUtil=new DbUtil();
try {
dbUtil.getCon();
System.out.println("数据库连接成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
4.3 管理员实体
package com.jakey.model;
public class Admin {
private int adminId;
private String adminName;
private String password;
public Admin() {
super();
// TODO Auto-generated constructor stub
}
public Admin(int adminId, String password) {
super();
this.adminId = adminId;
this.password = password;
}
public Admin(String adminName, String password) {
super();
this.adminName = adminName;
this.password = password;
}
public int getAdminId() {
return adminId;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
}
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
5、文件内容
6、源码获取
私信或者通过名片进行添加进行获取!!