⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 Task manager control code by java
💻 JAVA
字号:
package assign1;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.*;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

class ListProcess extends JFrame
{
    private static int DELAY = 1000;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     
    JPanel fullWindow;
    JTextArea textArea;
    JScrollPane scrollOne;

    String processList,fulloutput="";
    
    public ListProcess() throws IOException
    {
        processInfo();
        fullWindow =new JPanel();
        fullWindow.setBounds(5,5,755,535);
        fullWindow.setLayout(null);
        fullWindow.setVisible(true);
        fullWindow.setBackground(Color.LIGHT_GRAY);
        fullWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        
        textArea =new JTextArea();
        textArea.setBounds(10,10,745,525);
        textArea.setText(fulloutput);
        textArea.setEditable(false);

        scrollOne = new JScrollPane();
        scrollOne.setBounds(1,1,745,500);
        scrollOne.getViewport().add(textArea, null);
        scrollOne.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollOne.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        fullWindow.add(scrollOne);
        add(fullWindow);

        this.setLocation(screenSize.width/2-370,screenSize.height/2-270);  //end of centering
        this.setSize(760,540);
        this. setUndecorated(true);
        this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        this.setVisible(true);
        this.setResizable(false);
    }

    void processInfo() throws IOException
    {
        Runtime runtime = Runtime.getRuntime();
        //String command[] = {"cmd", "/c", "tasklist"};//xp
        String command = "ps aux"; //Linux//
        Process Allprocess = runtime.exec(command);
        InputStream inputstream = Allprocess.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

        while ((processList = bufferedreader.readLine()) != null)
        {
            fulloutput=fulloutput+processList+"\n";
            System.out.println(processList);
        }
    }


    public static void main(String[] args) throws IOException
    {
        
        ListProcess LoginPage=new ListProcess();
        LoginPage.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -