java捕获进程实时进度条

java捕获进程实时进度条,java,swing,time,process,Java,Swing,Time,Process,使用这个^I,我从保存为字符串的.txt文件中获取数据 对于我的进度条,我想知道这样的工作(或一般的方法等)是否可以计算(或类似的事情)需要完成的时间。这样我就可以在我的栏中实时显示处理时间 这有可能吗 编辑: new Scanner(new URL("SOME_URL.txt").openStream(), "UTF-8").useDelimiter("\\A").next(); package-app.gui; 导入java.awt.BorderLayout; 导入java.awt.Ev

使用这个^I,我从保存为字符串的.txt文件中获取数据

对于我的
进度条
,我想知道这样的工作(或一般的方法等)是否可以计算(或类似的事情)需要完成的时间。这样我就可以在我的
栏中实时显示
处理时间

这有可能吗

编辑:

new Scanner(new URL("SOME_URL.txt").openStream(), "UTF-8").useDelimiter("\\A").next();
package-app.gui;
导入java.awt.BorderLayout;
导入java.awt.EventQueue;
导入java.net.URL;
导入java.util.Scanner;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入javax.swing.JProgressBar;
导入javax.swing.UIManager;
导入javax.swing.UnsupportedLookAndFeelException;
导入org.apache.commons.io.IOUtils;
公共类更新程序{
私有JFrame;
私有静态字符串rawG;
私有静态字符串版本;
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
rawG=new Scanner(新URL(“SOME_URL.txt”).openStream(),“UTF-8”).useDelimiter(\\A”).next();
versI=IOUtils.toString(getClass().getClassLoader().getResourceAsStream(“version.txt”);
}捕获(例外e){
System.out.println(“错误类更新程序try/catch raw github”);
}
if(Integer.parseInt(rawG.split(\\”)[0])
可能吗?对使用Scanner.next()读取URL内容时是否可能?没有

您需要自己读取字节,并对其进行计数:

package app.gui;

    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.net.URL;
    import java.util.Scanner;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;

    import org.apache.commons.io.IOUtils;

    public class Updater {

        private JFrame frame;
        private static String rawG;
        private static String versI;

        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        rawG = new Scanner(new URL("SOME_URL.txt").openStream(), "UTF-8").useDelimiter("\\A").next();
                        versI = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("version.txt"));
                    } catch (Exception e) {
                        System.out.println("error class Updater try/catch raw github");
                    }
                    if (Integer.parseInt(rawG.split("\\.")[0]) < Integer.parseInt(versI.split("\\.")[0])) {
                        System.out.println("Version check failure, update needed");
                        try {
                            Updater window = new Updater();
                            window.frame.setVisible(true);
                        } catch (Exception e) {
                            System.out.println("error class Updater try/catch initialize frame");
                        }                   
                    } else {
                        System.out.println("Version check correct, no update needed");
                    }
                }
            });
        }

        public Updater() {
            initialize();
        }

        private void initialize() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                    | UnsupportedLookAndFeelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            frame = new JFrame();
            frame.setBounds(100, 100, 450, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel panel = new JPanel();
            frame.getContentPane().add(panel, BorderLayout.SOUTH);
            panel.setLayout(new BorderLayout(0, 0));

            JProgressBar progressBar = new JProgressBar();
            progressBar.setStringPainted(true);
            panel.add(progressBar, BorderLayout.NORTH);
        }

    }

可能吗?对使用Scanner.next()读取URL内容时是否可能?没有

您需要自己读取字节,并对其进行计数:

package app.gui;

    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.net.URL;
    import java.util.Scanner;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;

    import org.apache.commons.io.IOUtils;

    public class Updater {

        private JFrame frame;
        private static String rawG;
        private static String versI;

        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        rawG = new Scanner(new URL("SOME_URL.txt").openStream(), "UTF-8").useDelimiter("\\A").next();
                        versI = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("version.txt"));
                    } catch (Exception e) {
                        System.out.println("error class Updater try/catch raw github");
                    }
                    if (Integer.parseInt(rawG.split("\\.")[0]) < Integer.parseInt(versI.split("\\.")[0])) {
                        System.out.println("Version check failure, update needed");
                        try {
                            Updater window = new Updater();
                            window.frame.setVisible(true);
                        } catch (Exception e) {
                            System.out.println("error class Updater try/catch initialize frame");
                        }                   
                    } else {
                        System.out.println("Version check correct, no update needed");
                    }
                }
            });
        }

        public Updater() {
            initialize();
        }

        private void initialize() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                    | UnsupportedLookAndFeelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            frame = new JFrame();
            frame.setBounds(100, 100, 450, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel panel = new JPanel();
            frame.getContentPane().add(panel, BorderLayout.SOUTH);
            panel.setLayout(new BorderLayout(0, 0));

            JProgressBar progressBar = new JProgressBar();
            progressBar.setStringPainted(true);
            panel.add(progressBar, BorderLayout.NORTH);
        }

    }

我不清楚你所说的“处理时间”是什么意思。你想显示下载进度还是经过的时间?下载进度我不清楚你所说的“处理时间”是什么意思。你想显示下载进度还是经过的时间?下载进度