操作系统安全课程设计报告-0906130204-廖浩伟
List if(!checkEqual(xy,temp_memory_record)){ temp_memory_record.add(xy); } } D_memory_record = temp_memory_record; //物理内存使用百分量 float used_memory = ((float)monitorInfo.getUsedMemory()/(float)monitorInfo.getTotalMemorySize())*100; float point_memory = 130-(used_memory/100*130); XY xy_memory_record = new XY(); xy_memory_record.x1 = 370; xy_memory_record.y1 = (int)point_memory; xy_memory_record.x2 = 370+2; xy_memory_record.y2 = (int)point_memory; if(!checkEqual(xy_memory_record,D_memory_record)){ D_memory_record.add(xy_memory_record); } /* * CPU使用记录中的表格 */ for(int i = 0;i<10;i++){ XY xy = new XY(); xy.x1 = 0; xy.y1 = (i+1)*13; xy.x2 = 390; xy.y2 = (i+1)*13; if(!checkEqual(xy,X_cpu_record)){ X_cpu_record.add(xy); } } Y_cpu_record.clear(); for(int i = 0;i<70;i++){ XY xy = new XY(); xy.x1 = (i+1)*13-move; xy.y1 = 0; xy.x2 = (i+1)*13-move; - 29 - 操作系统安全课程设计报告-0906130204-廖浩伟 xy.y2 = 200; if(!checkEqual(xy,Y_cpu_record)){ Y_cpu_record.add(xy); } } //CPU使用记录中的数据 List if(!checkEqual(xy,temp_cpu_record)){ temp_cpu_record.add(xy); } } D_cpu_record = temp_cpu_record; //CPU使用百分量 float used_cpu = (float)(os.getSystemCpuLoad()*100); float point_cpu = 130-(used_cpu/100*130); XY xy_cpu_record = new XY(); xy_cpu_record.x1 = 370; xy_cpu_record.y1 = (int)point_cpu; xy_cpu_record.x2 = 370; xy_cpu_record.y2 = (int)point_cpu; if(!checkEqual(xy_cpu_record,D_cpu_record)){ D_cpu_record.add(xy_cpu_record); } //CPU两次数据之间的连接线 XY xy_cpu_record_connect = new XY(); xy_cpu_record_connect.x1 = temp_cpu_x; xy_cpu_record_connect.y1 = temp_cpu_y; xy_cpu_record_connect.x2 = 370; xy_cpu_record_connect.y2 = (int)point_cpu; if(!checkEqual(xy_cpu_record_connect,D_cpu_record)){ D_cpu_record.add(xy_cpu_record_connect); } temp_cpu_x = 370; temp_cpu_y = (int)point_cpu; } //检查队列中是否有重复数据 public boolean checkEqual(XY check_xy,List for(int i = 0;i - 30 - 操作系统安全课程设计报告-0906130204-廖浩伟 if((xy.x1 == check_xy.x1)&&(xy.y1 == check_xy.y1)&&(xy.x2 == check_xy.x2)&&(xy.y2 == check_xy.y2)){ return true; } } return false; } //输出队列中的数据 public void showData(List for(int i = 0;i System.out.println(\第\+i+\个: \+xy.x1+\+xy.y1+\\+xy.x2+\+xy.y2); } } 3.13刷新功能 // 时钟控制,自动刷新 public void autoFlush() throws Exception { Timer timeCount = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent evt) { try { //刷新得到系统信息的工具 monitorInfo = service.getMonitorInfoBean(); m.getHandleCount(); //图标每次左移的像素点 move = move+2; updateProcess(); updateService(); southPanel(); updateChart(); FunctionTab(); p_memory_record.repaint(); p_cpu_record.repaint(); p_cpu_used.repaint(); } catch (Exception update) { } } }); - 31 - 操作系统安全课程设计报告-0906130204-廖浩伟 timeCount.start(); } public void updateProcess() throws Exception { int flag = 0; String name = \; int rowIndex = 0; // 记录上次选中的行 if (pTable.getSelectedRow() != -1) { flag = 1; name = pTable.getValueAt(pTable.getSelectedRow(), 0).toString(); } else { flag = 0; } m.getProcessForWindows(); String c[][] = new String[m.processCount][5]; int j = 0; Vector srcdata = new Vector(); while (j < m.processCount) { c[j][0] = m.proce[j].getCaption(); c[j][1] = m.proce[j].getCSName(); c[j][2] = m.proce[j].getPriority(); c[j][3] = m.proce[j].getProcessId(); c[j][4] = m.proce[j].getThreadCount(); if (c[j][0].equals(name)) rowIndex = j; Vector rowdata = new Vector(5); for (int i = 0; i < 5; i++) rowdata.add(c[j][i]); // 将数据加入到容器,也就是加入到JTable 中 srcdata.add(rowdata); j++; } DefaultTableModel model0 = new DefaultTableModel(srcdata, pb); pTable.setModel(model0); if (flag == 1) pTable.setRowSelectionInterval(rowIndex, rowIndex); this.pTable.repaint(); this.pTable.updateUI(); - 32 - 操作系统安全课程设计报告-0906130204-廖浩伟 } public void updateService() throws Exception { int flag = 0; String name = \; int rowIndex = 0; // 记录上次选中的行 if (sTable.getSelectedRow() != -1) { flag = 1; name = sTable.getValueAt(sTable.getSelectedRow(), 0).toString(); } else { flag = 0; } m.getServiceForWindows(); String c[][] = new String[m.serviceCount][5]; int j = 0; Vector srcdata = new Vector(); while (j < m.serviceCount) { c[j][0] = m.servi[j].getName(); c[j][1] = m.servi[j].getProcessId(); c[j][2] = m.servi[j].getDisplayName(); c[j][3] = m.servi[j].getState(); c[j][4] = m.servi[j].getStartName(); if (c[j][0].equals(name)) rowIndex = j; Vector rowdata = new Vector(5); for (int i = 0; i < 5; i++) rowdata.add(c[j][i]); // 将数据加入到容器,也就是加入到JTable 中 srcdata.add(rowdata); j++; } DefaultTableModel model0 = new DefaultTableModel(srcdata, sb); sTable.setModel(model0); if (flag == 1) sTable.setRowSelectionInterval(rowIndex, rowIndex); this.sTable.repaint(); this.sTable.updateUI(); } - 33 -