JAVA Process Manager
ProcessViewer. java class, responsible for interface implementation
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 ("process terminated"); jbutton. addActionListener (new ActionListener () {@ Overridepublic void actionreceivmed (ActionEvent e) {String process = (String) jtable. getValueAt (jtable. getSelectedRow (), 0); try restarting runtime.getruntime(cmd.exe c ("taskkill/f/im" + process);} catch (IOException e1) {e1.printStackTrace ();} tasklist. init (); jtable. updateUI (); jpl. repaint (); System. out. println (process) ;}}); jbutton2 = new JButton ("Refresh process"); jbutton2.addActionListener (new ActionListener () {@ Overridepublic void actionreceivmed (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 ("Process Manager"); this. add (jpl, BorderLayout. CENTER); this. add (jplbutton, BorderLayout. SOUTH); this. setBounds (400,200,600,400); this. setVisible (true); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE);} public static void main (String [] args) {new ProcessViewer ();}}
TaskList. java class, which calls system processes and generates corresponding formats
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 = {"image name", "PID", "session name", "session #", "memory usage"}; public void init () {Process proc; try {proc = runtime.getruntime(cmd.exe c ("tasklist/NH/FO csv"); br = new BufferedReader (new InputStreamReader (proc. getInputStrea M (); 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 ();}}}