一个简单的swing界面。
以下是管理员端的部分代码:
//管理员端,包含查看、添加、修改和删除车辆信息和查看营业额的功能,其中添加和修改车辆信息单独有两个界面,所以单出写出两个类
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import ym.Main.Login;
import ym.entity.Che;
import ym.mapper.cheMapper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.List;
public class AdminClient extends JFrame implements ActionListener {
JTable table;
JLabel label1, label2, label3;
Object data[][];
Object name[] = {"编号", "车型","品牌", "价格", "颜色","天数", "租用否", "用户"};
JButton buttonOfAdd, buttonOfBrowse, buttonOfDelete, buttonOfLogout, buttonOfCheck, buttonOfTurnover,buttonOfSeek;
Box box1, box2;
JTextField fieldOfDelete, fieldOfCheck;
JPanel jPanel1, jPanel2;
Connection con = null;
Statement state = null;
ResultSet rs = null;
public AdminClient(Boolean flag) throws IOException {
init();
setVisible(true);
setBounds(650, 270, 610, 540);
setTitle("车辆租赁系统管理界面");
if (flag) //flag是一个boolean类型,如果为true,打开此窗口直接信息浏览,false表里面没有信息,需要点击信息浏览!
{
mybatisInfo();
}
}
void init() {
label1 = new JLabel("");
buttonOfBrowse = new JButton("所有车辆信息");
buttonOfBrowse.addActionListener(this);
buttonOfAdd = new JButton(" 添加车辆 ");
buttonOfAdd.addActionListener(this);
buttonOfDelete = new JButton(" 删除 ");
buttonOfDelete.addActionListener(this);
buttonOfLogout = new JButton(" 退 出 登 录 ");
buttonOfLogout.addActionListener(this);
buttonOfCheck = new JButton(" 查看 & 修改 ");
buttonOfCheck.addActionListener(this);
buttonOfSeek = new JButton("租期较高");
buttonOfSeek.addActionListener(this);
buttonOfTurnover = new JButton("查看营业额");
buttonOfTurnover.addActionListener(this);
label2 = new JLabel("待删除车辆编号:");
label3 = new JLabel("待查看车辆编号:");
fieldOfDelete = new JTextField();
fieldOfCheck = new JTextField();
data = new Object[50][10];
table = new JTable(data, name);//组件的创建
table.setEnabled(false);
JScrollPane scrollPane = new JScrollPane(table);
box1 = Box.createVerticalBox();
box1.add(Box.createVerticalStrut(10));
box1.add(buttonOfBrowse);
box1.add(Box.createVerticalStrut(20));
box1.add(buttonOfAdd);
box1.add(Box.createVerticalStrut(25));
box1.add(label3);
box1.add(Box.createVerticalStrut(5));
box1.add(fieldOfCheck);
box1.add(Box.createVerticalStrut(5));
box1.add(buttonOfCheck);
box1.add(Box.createVerticalStrut(25));
box1.add(label2);
box1.add(Box.createVerticalStrut(5));
box1.add(fieldOfDelete);
box1.add(Box.createVerticalStrut(5));