用swing组件写出一个完整的酒店管理系统,并连接数据库
时间: 2023-03-23 22:03:05 浏览: 111
JavaSwing窗体项目 酒店房间管理系统 带数据库
5星 · 资源好评率100%
好的,下面是一个使用Swing组件编写的完整的酒店管理系统,并连接到数据库的示例代码:
```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class HotelManagementSystem extends JFrame implements ActionListener {
JMenuBar mb;
JMenu m1, m2;
JMenuItem i1, i2, i3, i4;
JLabel l1, l2;
HotelManagementSystem() {
mb = new JMenuBar();
add(mb);
m1 = new JMenu("管理");
mb.add(m1);
m2 = new JMenu("帮助");
mb.add(m2);
i1 = new JMenuItem("添加客房");
i1.addActionListener(this);
m1.add(i1);
i2 = new JMenuItem("客房列表");
i2.addActionListener(this);
m1.add(i2);
i3 = new JMenuItem("删除客房");
i3.addActionListener(this);
m1.add(i3);
i4 = new JMenuItem("退出");
i4.addActionListener(this);
m1.add(i4);
l1 = new JLabel("欢迎来到酒店管理系统");
l1.setBounds(200, 50, 400, 30);
l1.setForeground(Color.BLUE);
l1.setFont(new Font("Tahoma", Font.PLAIN, 30));
add(l1);
l2 = new JLabel();
l2.setBounds(0, 0, 1000, 750);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("hotelmanagementsystem/icons/second.jpg"));
Image i2 = i1.getImage().getScaledInstance(1000, 750, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
l2.setIcon(i3);
add(l2);
setLayout(null);
setBounds(0, 0, 1000, 750);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("添加客房")) {
new AddRoom().setVisible(true);
} else if (ae.getActionCommand().equals("客房列表")) {
new Room().setVisible(true);
} else if (ae.getActionCommand().equals("删除客房")) {
new RemoveRoom().setVisible(true);
} else if (ae.getActionCommand().equals("退出")) {
System.exit(0);
}
}
public static void main(String[] args) {
new HotelManagementSystem().setVisible(true);
}
}
class AddRoom extends JFrame implements ActionListener {
JTextField t1, t2, t3, t4, t5;
JComboBox c1, c2, c3;
JButton b1, b2;
AddRoom() {
JLabel l1 = new JLabel("客房号");
l1.setBounds(20, 30, 100, 20);
add(l1);
t1 = new JTextField();
t1.setBounds(130, 30, 150, 20);
add(t1);
JLabel l2 = new JLabel("客房类型");
l2.setBounds(20, 80, 100, 20);
add(l2);
c1 = new JComboBox(new String[] { "单人间", "双人间", "套房" });
c1.setBounds(130, 80, 150, 20);
add(c1);
JLabel l3 = new JLabel("客房价格");
l3.setBounds(20
阅读全文