JAVA版进程管理器
来源:互联网 发布:手机扫描扑克牌软件 编辑:程序博客网 时间:2024/05/21 11:00
ProcessViewer.java 类,负责界面实现
import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.ListSelectionModel;public class ProcessViewer extends JFrame{private BorderLayout borderlayout = new BorderLayout();private FlowLayout flowlayout = new FlowLayout(FlowLayout.RIGHT);private JPanel jpl = new JPanel();private JPanel jplbutton = new JPanel();private JTable jtable;private JButton jbutton;private JButton jbutton2;private JScrollPane jscrollPane;public ProcessViewer(){TaskList tasklist = new TaskList();tasklist.init();jtable = new JTable(tasklist.result,tasklist.title);jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jscrollPane = new JScrollPane(jtable); jbutton = new JButton("结束进程"); jbutton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String process = (String) jtable.getValueAt(jtable.getSelectedRow(), 0);try {Runtime.getRuntime().exec("taskkill /f /im "+process);} catch (IOException e1) {e1.printStackTrace();}tasklist.init();jtable.updateUI();jpl.repaint();System.out.println(process);} }); jbutton2 = new JButton("刷新进程"); jbutton2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {tasklist.init();jtable.updateUI();jpl.repaint();} });jpl.setLayout(borderlayout);jpl.add(jscrollPane);jplbutton.setLayout(flowlayout);jplbutton.add(jbutton2);jplbutton.add(jbutton);this.pack();this.setTitle("进程管理器");this.add(jpl,BorderLayout.CENTER);this.add(jplbutton,BorderLayout.SOUTH);this.setBounds(400, 200, 600, 400);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public static void main(String[] args) {new ProcessViewer();}}
TaskList.java 类,负责调用系统进程并生成相应格式
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class TaskList {public BufferedReader br=null;public String [][] result=new String[100][5];public String [] title={"映像名称","PID","会话名","会话#","内存使用"};public void init(){Process proc;try {proc = Runtime.getRuntime().exec("tasklist /NH /FO csv");br=new BufferedReader(new InputStreamReader(proc.getInputStream())); String res=null;int x = 0; while((res=br.readLine())!=null){ String[] value=res.replace("\",\"", ";").replace("\"", "").split(";"); if(value.length==5){ for(int i = 0;i<5;i++){ result[x][i] = value[i]; } } x++; if(x==100) break; }} catch (IOException e) {e.printStackTrace();} }}
0 0
- JAVA版进程管理器
- 进程管理器
- Java调用批处理或可执行文件和Runtime、Process类实现Java版进程管理器
- Java版代码管理器
- 修改进程管理器中Java程序显示的映像名称
- 内存与进程管理器
- 自己动手写进程管理器
- 进程管理器 下载
- 自制进程管理器
- 任务管理器进程
- 自制进程管理器
- MFC 进程管理器
- VB模拟进程管理器
- winform:进程管理器
- 任务管理器看进程
- 37、进程管理器--界面设计
- node pm2进程管理器
- 进程管理器(一)
- c# 四舍五入、上取整、下取整
- C# 引用 VC 函数 平常积累
- C++第一遍泛读
- Android studio 安装过程提示找不到JDK
- 手游研发—纹理优化相关
- JAVA版进程管理器
- Android 多屏幕适配
- win7设置共享文件夹
- 阿发福利科技科技科技了
- Linux安装xdebug.(Debian,Ubuntu)
- css视频笔记整理
- 项目管理的本质
- 计算机组成原理总结
- http://blog.sciencenet.cn/blog-630522-491356.html