【技能实训】DMS数据挖掘项目-Day13

文章目录

  • 任务15
    • 【任务15.1】ClientFrame.java
    • 【任务15.2】ClientFrame.java
    • 【任务15.3】实现匹配日志信息或物流数据的数据保存功能(保存到本地文件),将15.2中,返回的匹配数据,保存到客户端文件中
    • 【任务15.4】实现物流信息和日志信息的表格显示功能
    • 【任务15.5】测试日志或物流信息的采集、匹配、匹配的日志、物流信息的数据库保存和显示功能(截图)
    • 【任务15.6】在日志和物流采集卡片中,新增两Tab,实现没有匹配的数据的显示功能。可以参考匹配数据的显示。(代码截图+运行截图)

任务15

【技能实训】DMS数据挖掘项目-Day13_第1张图片

【任务15.1】ClientFrame.java

实现匹配日志数据功能

//菜单项 注册监听
miMatchLog.addActionListener(new MatchLogListener());

// 工具栏按钮项,注册监听
btnMatchLog.addActionListener(new MatchLogListener());


// 匹配日志信息监听类
	private class MatchedLogRecListener implements ActionListener{

			@Override
			public void actionPerformed(ActionEvent e) {
						//参考前面字符控制界面,自己完成代码


           }
    }

程序设计

// 匹配日志信息监听类
private class MatchedLogRecListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        //参考前面字符控制界面,自己完成代码
        try {
            if(LogRecService.readLogRecs().size()>0){
                JOptionPane.showMessageDialog(null, "日志数据匹配成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
            } else{
                JOptionPane.showMessageDialog(null, "日志数据匹配失败!", "警告" , JOptionPane. WARNING_MESSAGE);
            }
        }catch (Exception t){
            JOptionPane.showMessageDialog(null, "日志数据匹配失败!", "警告" , JOptionPane. WARNING_MESSAGE);
        }
    }
}

【任务15.2】ClientFrame.java

实现匹配物流数据功能

// 菜单项 注册监听
miMatchTrans.addActionListener(new MatchTransListener());

// 注册监听
btnMatchTrans.addActionListener(new MatchTransListener());




// 匹配物流信息监听类
private class MatchedTransportListener implements ActionListener{

			@Override
			public void actionPerformed(ActionEvent e) {
	          //参考前面字符控制界面,自己完成代码

           }
    }

程序设计

// 匹配物流信息监听类
private class MatchedTransportListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        //参考前面字符控制界面,自己完成代码
        try {
            if (TransportService.readTransports().size()>0) {
                JOptionPane.showMessageDialog(null, "物流数据匹配成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "物流数据匹配失败!", "警告", JOptionPane.WARNING_MESSAGE);
            }
        } catch (Exception t) {
            JOptionPane.showMessageDialog(null, "物流数据匹配失败!", "警告", JOptionPane.WARNING_MESSAGE);
        }
    }
}

【任务15.3】实现匹配日志信息或物流数据的数据保存功能(保存到本地文件),将15.2中,返回的匹配数据,保存到客户端文件中

// 菜单项 注册监听
miSave.addActionListener(new SaveDataListener());

// 工具栏项 注册监听
btnSave.addActionListener(new SaveDataListener());


// 保存数据监听类
	private class SaveDataListener implements ActionListener {
		// 数据保存的事件处理方法
		public void actionPerformed(ActionEvent e) {
			      //调用LogRecServer和TransportService中定义的数据保存方法完成数据的保存,保存成功或失败,都要弹出对话框给出提示。
			}
		}
	}

程序设计

private class SaveActionListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            LogRecService.saveLogRec(logList);
            TransportService.saveTransport(transList);

            logList.clear();
            transList.clear();
            JOptionPane.showMessageDialog(null, "保存成功!", "提示" , JOptionPane. INFORMATION_MESSAGE);
        }catch (Exception t){
            JOptionPane.showMessageDialog(null, "保存失败!", "警告" , JOptionPane. WARNING_MESSAGE);
        }
    }
}

【任务15.4】实现物流信息和日志信息的表格显示功能

显示的数据来源于客户端的临时数据文件,从文件中读取所有的数据,存储到List集合中,然后创建TableModel为JTable提供数据。
【技能实训】DMS数据挖掘项目-Day13_第2张图片

创建表格Model,为JTable提供数据:

在com.qst.dms.entity类下创建DataTableModelFromList,继承AbstractTableModel,这里用到泛型。

// 使用List来创建TableModel
	private List<String[]> datas=new ArrayList<>();
	// 标志位,区分日志和物流:1,日志;0,物流
	private int sign;

	public DataTableModelFromList(List<T> data, int sign) {
		// TODO Auto-generated constructor stub
    	this.sign = sign;
     
		for(T obj: data) {
			try {
				String[] arr = (String[])obj.getClass().getMethod("toArray").invoke(obj);
				datas.add(arr);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}

	}

	// 获取表格的行数
	public int getRowCount() {
		return datas.size();
	}

	// 获取表格的列数
	public int getColumnCount() {
		return this.sign==1?7:7;
	}

	// 获取指定位置的值
	public Object getValueAt(int rowIndex, int columnIndex) {
		return datas.get(rowIndex)[columnIndex];
	}

	// 获取表头信息
	public String getColumnName(int column) {
		String[] logArray = { "日志ID", "采集时间", "采集地点", "状态", "用户名", "IP", "日志类型" };
		String[] tranArray = { "物流ID", "采集时间", "目的地", "状态", "经手人", "收货人",
				"物流类型" };
		return sign == 1 ? logArray[column] : tranArray[column];
	}
	
// 菜单项,注册监听
miShow.addActionListener(new ShowDataListener());

// 工具栏项 注册监听
btnShow.addActionListener(new ShowDataListener());
//数据显示监听类

【技能实训】DMS数据挖掘项目-Day13_第3张图片

// 刷新日志选项卡,显示日志信息表格

flush

// 刷新物流选项卡,显示物流信息表格

flush

程序设计

package com.qst.dms.entity;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

public class DataTableModelFromList<T> extends AbstractTableModel {
    // 使用List来创建TableModel
    private ArrayList<String[]> datas=new ArrayList<>();
    // 标志位,区分日志和物流:1,日志;0,物流
    private int sign;

    public DataTableModelFromList(ArrayList<T> data, int sign) {
        // TODO Auto-generated constructor stub
        this.sign = sign;

        for(T obj: data) {
            try {
                String[] arr = (String[])obj.getClass().getMethod("toArray").invoke(obj);
                datas.add(arr);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }

    // 获取表格的行数
    public int getRowCount() {
        return datas.size();
    }

    // 获取表格的列数
    public int getColumnCount() {
        return this.sign==1?7:7;
    }

    // 获取指定位置的值
    public Object getValueAt(int rowIndex, int columnIndex) {
        return datas.get(rowIndex)[columnIndex];
    }

    // 获取表头信息
    public String getColumnName(int column) {
        String[] logArray = { "日志ID", "采集时间", "采集地点", "状态", "用户名", "IP", "日志类型" };
        String[] tranArray = { "物流ID", "采集时间", "目的地", "状态", "经手人", "收货人",
                "物流类型" };
        return sign == 1 ? logArray[column] : tranArray[column];
    }

}

【任务15.5】测试日志或物流信息的采集、匹配、匹配的日志、物流信息的数据库保存和显示功能(截图)

【技能实训】DMS数据挖掘项目-Day13_第4张图片
【技能实训】DMS数据挖掘项目-Day13_第5张图片

【任务15.6】在日志和物流采集卡片中,新增两Tab,实现没有匹配的数据的显示功能。可以参考匹配数据的显示。(代码截图+运行截图)

提示:创建一个非匹配日志显示方法:void initGatherLogRecShowUI()
(1)使用DataTableModelFromList,以非匹配的结合为参数,创建要给TableModel为JTable提供数据
(2)创建要给JTable对象(名称为logTable)
(3)将这个logTable添加到jGather卡片中
非匹配物流数据的显示方法类似实现

程序设计

private void initGatherLogRecShowUI(){
    JPanel pLog = new JPanel();
    jGather.addTab("日志数据显示", pLog);
    pLog.setLayout(new BoxLayout(pLog, BoxLayout.Y_AXIS));
}

private void initGatherTransportShowUI(){
    JPanel pLog = new JPanel();
    jGather.addTab("物流数据显示", pLog);
    pLog.setLayout(new BoxLayout(pLog, BoxLayout.Y_AXIS));
}

private void flushGatherLogRecShowUI(){
    DataTableModelFromList<LogRec> logModel = new DataTableModelFromList<>(logList,1);
    JTable logTable = new JTable(logModel);
    jGather.addTab("日志数据显示",new JScrollPane(logTable));
}

private  void flushGatherTransportShowUI(){
    DataTableModelFromList<Transport> logModel = new DataTableModelFromList<>(transList,2);
    JTable transTable = new JTable(logModel);
    jGather.addTab("物流数据显示",new JScrollPane(transTable));
}

【技能实训】DMS数据挖掘项目-Day13_第6张图片
【技能实训】DMS数据挖掘项目-Day13_第7张图片

完整程序

package com.qst.dms.ui;

import com.qst.dms.entity.*;
import com.qst.dms.service.LogRecService;
import com.qst.dms.service.TransportService;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ClientFrame extends JFrame {
    //菜单
    private JMenuBar menuBar;//包含多个菜单
    private JMenu oper, help, matchMenu;
    private JMenuItem mGather, mSave, mSend, mShow, mCheck, mHelp, mLog, mTransport, mExit;

    //工具栏mShow,showBtn
    private JToolBar toolBar;
    private JButton gatherBtn, logBtn, transportBtn, saveBtn, sendBtn, showBtn;

    //数据采集和显示卡片布局组件
    private JPanel p;//数据采集和显示的界面面板,里面采用CardLayout布局,分别显示采集界面和显示界面
    private JTabbedPane jGather, jShow;
    private CardLayout card;

    //日志数据采集组件
    private JTextField txtLogId, txtName, txtLocation, txtIP;
    private JRadioButton rbLogin, rbLogout;
    private JButton btnLogConfirm, btnLogReset;

    //物流数据采集组件
    private JTextField txtTransId, txtAdress, txtHandler, txtReceiver;
    private JComboBox<String> cmbTanStatus;
    private JButton btnTranConfirm, btnTranReset;

    private JTable logTable;//日志原始数据显示Table
    private JTable transTable;//物流原始数据显示Table

    //日志数据存储集合
    private ArrayList<LogRec> logList = new ArrayList<>();
    private ArrayList<MatchedLogRec> matchLogList = new ArrayList<>();
    //物流数据存储集合
    private ArrayList<Transport> transList = new ArrayList<>();
    private ArrayList<MatchedTransport> matchTransList = new ArrayList<>();

    //日志与物流业务对象
    private LogRecService logRecService = new LogRecService();
    private TransportService transService = new TransportService();

    private String serverIp;//服务端IP
    private int serverPort;//服务端端口

    //客户端配置文件
    private final static String CONFIG_FILE = "config/client.properties";

    private void initConfig() {
        try {
            //通过Properties类获取配置文件中的属性赋值给serverPort和serverIp


        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    // 构造方法
    public ClientFrame() {
        // TODO Auto-generated constructor stub
        super("DMS客户端");//给窗口一个名称,显示左上角
        ImageIcon icon = new ImageIcon("images\\dms.png");
        this.setIconImage(icon.getImage());

        initConfig();//读取配置文件
        initMenu();//初始化菜单
        initToolBar();//初始化工具栏


//--------数据采集界面的设计----------
        //后面补充代码
        card = new CardLayout();
        p = new JPanel(card);
        this.getContentPane().add(p, BorderLayout.CENTER);
        jGather = new JTabbedPane(JTabbedPane.TOP);
        p.add(jGather, "gather");
        jShow = new JTabbedPane(JTabbedPane.TOP);
        jShow.addTab("日志", new JScrollPane());
        jShow.addTab("物流", new JScrollPane());
        p.add(jShow, "show");

        initLogGatherGUI();
        initGatherTransport();

        initGatherLogRecShowUI();
        initGatherTransportShowUI();


//--------数据采集界面的设计结束----------


        //数据采集的监听

        mGather.addActionListener(new miGatherListener());//数据采集菜单项增加监听
        gatherBtn.addActionListener(new miGatherListener());//工具栏上采集按钮监听


        //数据显示监听
        mShow.addActionListener(new miShowListener());
        showBtn.addActionListener(new miShowListener());


        //帮助菜单的监听设置

        // 注册监听
        mHelp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // 显示消息对话框
                JOptionPane.showMessageDialog(null, "本系统实现数据的采集、过滤分析匹配、保存、发送及显示功能", "帮助", JOptionPane.QUESTION_MESSAGE);
            }
        });
        // 注册监听
        mCheck.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // 显示消息对话框
                JOptionPane.showMessageDialog(null, "版本:1.0版", "关于", JOptionPane.WARNING_MESSAGE);
            }
        });

        //initGatherLogRecShowUI();//日志显示界面初始化
        //initGatherTransportShowUI();//物流采集界面初始化

        // 设置窗体大小
        this.setSize(600, 400);
        // 设置窗口在屏幕中央
        this.setLocationRelativeTo(null);//居中
        // 设置默认的关闭按钮操作为退出程序
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 设置窗体初始可见
        this.setVisible(true);
    }

    // 初始化菜单的方法
    private void initMenu() {

        //-------系统菜单的初始化开始----------------
        menuBar = new JMenuBar();
        this.setJMenuBar(menuBar);//创建菜单条,并放入到JFrame

        oper = new JMenu("操作");
        help = new JMenu("帮助");
        menuBar.add(oper);
        menuBar.add(help);

        mGather = new JMenuItem("采集数据");

        mGather.addActionListener(new miGatherListener());

        //子菜单
        matchMenu = new JMenu("匹配数据");
        mLog = new JMenuItem("日志数据匹配");
        mLog.addActionListener(new MatchedLogRecListener());
        mTransport = new JMenuItem("物流数据匹配");
        mTransport.addActionListener(new MatchedTransportListener());
        matchMenu.add(mLog);
        matchMenu.add(mTransport);

        mSave = new JMenuItem("保存数据");
        mSave.addActionListener(new SaveActionListener());

        mSend = new JMenuItem("发送数据");
        mSend.addActionListener(new SendActionListener());
        mShow = new JMenuItem("显示数据");

        mExit = new JMenuItem("退出应用");

        mExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                System.exit(0);
            }

        });

        oper.add(mGather);
        oper.add(matchMenu);
        oper.add(mSave);
        oper.add(mSend);
        oper.add(mShow);
        oper.add(mExit);

        mCheck = new JMenuItem("关于系统");
        mHelp = new JMenuItem("查看帮助");
        help.add(mCheck);
        help.add(mHelp);

        //-------系统菜单的初始化结束----------------
    }

    // 初始化工具栏的方法
    private void initToolBar() {

        //-------系统工具栏的初始化------------
        toolBar = new JToolBar();

        ImageIcon icon1 = new ImageIcon("images\\gatherData.png");

        gatherBtn = new JButton("采集数据", icon1);

        gatherBtn.addActionListener(new miGatherListener());

        ImageIcon icon2 = new ImageIcon("images\\matchData.png");
        logBtn = new JButton("日志数据匹配", icon2);
        logBtn.addActionListener(new MatchedLogRecListener());//-----------------
        ImageIcon icon3 = new ImageIcon("images\\matchData.png");
        transportBtn = new JButton("物流数据匹配", icon3);
        transportBtn.addActionListener(new MatchedTransportListener());//------------
        ImageIcon icon4 = new ImageIcon("images\\saveData.png");
        saveBtn = new JButton("保存数据", icon4);
        saveBtn.addActionListener(new SaveActionListener());
        ImageIcon icon5 = new ImageIcon("images\\sendData.png");
        sendBtn = new JButton("发送数据", icon5);
        sendBtn.addActionListener(new SendActionListener());
        ImageIcon icon6 = new ImageIcon("images\\showData.png");
        showBtn = new JButton("显示数据", icon6);

        toolBar.add(gatherBtn);
        toolBar.add(logBtn);
        toolBar.add(transportBtn);
        toolBar.add(saveBtn);
        toolBar.add(sendBtn);
        toolBar.add(showBtn);

        //JFrame默认有个JPanel
        this.getContentPane().add(toolBar, BorderLayout.NORTH);

        //-------系统工具栏的初始化结束------------
    }

    // 初始化日志数据采集界面的方法
    private void initLogGatherGUI() {
        JPanel pLog = new JPanel();
        jGather.addTab("日志", pLog);
        pLog.setLayout(new BoxLayout(pLog, BoxLayout.Y_AXIS));

        JPanel pLogId = new JPanel();
        pLog.add(pLogId);
        pLogId.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

        JLabel lblLogId = new JLabel("日志ID:");
        pLogId.add(lblLogId);

        txtLogId = new JTextField();
        txtLogId.setPreferredSize(new Dimension(100, 20));
        pLogId.add(txtLogId);

        JPanel pName = new JPanel();
        pLog.add(pName);
        pName.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

        JLabel lblName = new JLabel("用户名:");
        pName.add(lblName);

        txtName = new JTextField();
        txtName.setPreferredSize(new Dimension(100, 20));
        pName.add(txtName);

        JPanel pLocation = new JPanel();
        pLog.add(pLocation);

        JLabel lblLocation = new JLabel("登录地点:");
        pLocation.add(lblLocation);

        txtLocation = new JTextField();
        txtLocation.setPreferredSize(new Dimension(100, 20));
        pLocation.add(txtLocation);

        JPanel pIP = new JPanel();
        pLog.add(pIP);

        JLabel lblIP = new JLabel("登录IP:");
        pIP.add(lblIP);

        txtIP = new JTextField();
        txtIP.setPreferredSize(new Dimension(100, 20));
        pIP.add(txtIP);

        JPanel pLogStatus = new JPanel();
        pLog.add(pLogStatus);

        JLabel lblLogStatus = new JLabel("登录状态:");
        pLogStatus.add(lblLogStatus);

        rbLogin = new JRadioButton("登录");
        pLogStatus.add(rbLogin);
        rbLogin.setSelected(true);

        rbLogout = new JRadioButton("登出");
        pLogStatus.add(rbLogout);

        ButtonGroup bg = new ButtonGroup();
        bg.add(rbLogin);
        bg.add(rbLogout);

        JPanel pLogButton = new JPanel();
        pLog.add(pLogButton);

        btnLogConfirm = new JButton("确认");
        // 添加确认按钮监听
        btnLogConfirm.addActionListener(new GatherLogListener());
        pLogButton.add(btnLogConfirm);

        btnLogReset = new JButton("重置");
        // 添加重置按钮监听
        btnLogReset.addActionListener(new ResetListener());
        pLogButton.add(btnLogReset);
    }

    // 初始化物流数据采集界面的方法
    private void initGatherTransport() {
        //-----物流数据采集详情界面------
        JPanel pTran = new JPanel();
        jGather.addTab("物流", new JScrollPane(pTran));
        pTran.setLayout(new BoxLayout(pTran, BoxLayout.Y_AXIS));

        JPanel pTransId = new JPanel();
        pTran.add(pTransId);

        JLabel lblTransId = new JLabel("物流ID: ");
        pTransId.add(lblTransId);

        txtTransId = new JTextField();
        txtTransId.setPreferredSize(new Dimension(100, 20));
        pTransId.add(txtTransId);

        JPanel pAdress = new JPanel();
        pTran.add(pAdress);

        JLabel lblAdress = new JLabel("目的地:");
        pAdress.add(lblAdress);

        txtAdress = new JTextField();
        txtAdress.setPreferredSize(new Dimension(100, 20));
        pAdress.add(txtAdress);

        JPanel pHandler = new JPanel();
        pTran.add(pHandler);

        JLabel lblHandler = new JLabel("经手人");
        pHandler.add(lblHandler);

        txtHandler = new JTextField();
        txtHandler.setPreferredSize(new Dimension(100, 20));
        pHandler.add(txtHandler);

        JPanel pReceiver = new JPanel();
        pTran.add(pReceiver);

        JLabel lblReceiver = new JLabel("收货人:");
        pReceiver.add(lblReceiver);

        txtReceiver =new JTextField();
        txtReceiver.setPreferredSize(new Dimension(100,20));
        pReceiver.add(txtReceiver);

        JPanel pTranStatus = new JPanel();
        pTran.add(pTranStatus);

        JLabel lblTranStatus =new JLabel("物流状态:");
        pTranStatus.add(lblTranStatus);

        String[] tranStatus = new String[] {"发货中","送货中", "已签收"};
        cmbTanStatus=new JComboBox<String>(tranStatus);
        pTranStatus.add(cmbTanStatus);
        JPanel pTranButton=new JPanel();
        pTran.add(pTranButton);

        btnTranConfirm=new JButton("确认");
        btnTranConfirm.addActionListener(new GatherTransListener());
        pTranButton.add(btnTranConfirm);

        btnTranReset=new JButton("重置");
        btnTranReset.addActionListener(new ResetListener());
        pTranButton.add(btnTranReset);
    }


    private void initGatherLogRecShowUI(){
        JPanel pLog = new JPanel();
        jGather.addTab("日志数据显示", pLog);
        pLog.setLayout(new BoxLayout(pLog, BoxLayout.Y_AXIS));
    }

    private void initGatherTransportShowUI(){
        JPanel pLog = new JPanel();
        jGather.addTab("物流数据显示", pLog);
        pLog.setLayout(new BoxLayout(pLog, BoxLayout.Y_AXIS));
    }

    private void flushGatherLogRecShowUI(){
        DataTableModelFromList<LogRec> logModel = new DataTableModelFromList<>(logList,1);
        JTable logTable = new JTable(logModel);
        jGather.addTab("日志数据显示",new JScrollPane(logTable));
    }

    private  void flushGatherTransportShowUI(){
        DataTableModelFromList<Transport> logModel = new DataTableModelFromList<>(transList,2);
        JTable transTable = new JTable(logModel);
        jGather.addTab("物流数据显示",new JScrollPane(transTable));
    }

    // 数据采集监听类
    private class miGatherListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            card.show(p, "gather");
        }

    }


    // 匹配日志信息监听类
    private class MatchedLogRecListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            //参考前面字符控制界面,自己完成代码
            try {
                if(LogRecService.readLogRecs().size()>0){
                    JOptionPane.showMessageDialog(null, "日志数据匹配成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
                } else{
                    JOptionPane.showMessageDialog(null, "日志数据匹配失败!", "警告" , JOptionPane. WARNING_MESSAGE);
                }
            }catch (Exception t){
                JOptionPane.showMessageDialog(null, "日志数据匹配失败!", "警告" , JOptionPane. WARNING_MESSAGE);
            }
        }
    }

    // 匹配物流信息监听类
    private class MatchedTransportListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            //参考前面字符控制界面,自己完成代码
            try {
                if (TransportService.readTransports().size()>0) {
                    JOptionPane.showMessageDialog(null, "物流数据匹配成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
                }else{
                    JOptionPane.showMessageDialog(null, "物流数据匹配失败!", "警告", JOptionPane.WARNING_MESSAGE);
                }
            } catch (Exception t) {
                JOptionPane.showMessageDialog(null, "物流数据匹配失败!", "警告", JOptionPane.WARNING_MESSAGE);
            }
        }
    }

    private class SaveActionListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                LogRecService.saveLogRec(logList);
                TransportService.saveTransport(transList);

                logList.clear();
                transList.clear();
                JOptionPane.showMessageDialog(null, "保存成功!", "提示" , JOptionPane. INFORMATION_MESSAGE);
            }catch (Exception t){
                JOptionPane.showMessageDialog(null, "保存失败!", "警告" , JOptionPane. WARNING_MESSAGE);
            }
        }
    }

    private class SendActionListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            //参考前面字符控制界面,自己完成代码
            card.show(p,"send");
        }
    }


    // 日志数据采集监听类
    private class GatherLogListener implements ActionListener {
        // 数据采集的事件处理方法
        public void actionPerformed(ActionEvent e) {
            // 获取日志ID
            int id = Integer. parseInt(txtLogId. getText(). trim());
            // 创建当前时间
            Date currentDate = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = dateFormat.format(currentDate);

            // 获取地址栏地址
            String adress = txtLocation. getText(). trim();
            // 设置数据类型为:采集
            int type = DataBase. GATHER;
            // 获取用户姓名
            String user = txtName. getText(). trim();
            // 获取ip地址
            String ip = txtIP. getText(). trim();
            // 设置日志类型
            int logType = rbLogin. isSelected() ? LogRec. LOG_IN: LogRec. LOG_OUT;
            // 将数据封装到日志对象
            LogRec log = new LogRec(id, time, adress, type, user, ip, logType);
            // 将日志对象添加到日志列表
            logList.add(log);

            jGather.removeAll();

            initLogGatherGUI();
            initGatherTransport();

            flushGatherLogRecShowUI();
            flushGatherTransportShowUI();
            //logTable.updateUI();//更新了JTable的数据来源List,更新JTable界面

            // 显示对话框
            JOptionPane.showMessageDialog(null, "日志采集成功!", "提示" , JOptionPane. INFORMATION_MESSAGE);
        }
    }


    // 物流数据采集监听类
    private class GatherTransListener implements ActionListener {
        // 数据采集的事件处理方法
        public void actionPerformed(ActionEvent e) {
            // 获取物流ID
            int id = Integer. parseInt(txtTransId. getText(). trim());
            // 创建当前时间
            Date currentDate = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = dateFormat.format(currentDate);
            // 获取地址栏地址
            String adress = txtAdress. getText(). trim();
            // 设置数据类型为: 采集
            int type = DataBase. GATHER;
            // 获取经手人信息
            String handler = txtHandler. getText(). trim();
            // 获取发送人信息
            String reciver = txtReceiver. getText(). trim();
            // 设置物流类型
            int transportType = cmbTanStatus. getSelectedIndex() +1;
            // 将数据包装成物流对象
            Transport trans = new Transport(id, time, adress, type, handler, reciver, transportType);
            // 将物流对象放入物流列表
            transList. add(trans);

            jGather.removeAll();
            initLogGatherGUI();
            initGatherTransport();
            flushGatherLogRecShowUI();
            flushGatherTransportShowUI();

            //logTable.updateUI();

            // 显示对话框
            JOptionPane. showMessageDialog(null, "物流采集成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
        }
    }

    // 重置按钮监听类
    private class ResetListener implements ActionListener {
        // 重置按钮的事件处理方法
        public void actionPerformed(ActionEvent e) {
            txtName.setText("");
            txtLocation.setText("");
            txtIP.setText("");
            txtAdress.setText("");
            txtHandler.setText("");
            txtReceiver.setText("");
        }
    }

    private  class miShowListener implements  ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            card.show(p, "show");

            jShow.removeAll();

            ClientFrame.this.flushMatchedLogTable();
            ClientFrame.this.flushMatchedTransTable();
        }
    }

    private void flushMatchedLogTable(){
        DataTableModelFromList<LogRec> logModel = new DataTableModelFromList<>(logRecService.readLogRecs(),1);
        JTable logTable = new JTable(logModel);
        jShow.addTab("日志",new JScrollPane(logTable));
    }

    private  void flushMatchedTransTable(){
        DataTableModelFromList<Transport> logModel = new DataTableModelFromList<>(transService.readTransports(),2);
        JTable transTable = new JTable(logModel);
        jShow.addTab("物流",new JScrollPane(transTable));
    }


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new ClientFrame();
    }

}

你可能感兴趣的:(《,技能实训,》,java,前端)