Using Progress Bar in java apps

Using Progress Bar in java apps

Please, i am writing a program in java to read a file, perform some operation on each line of the file and them write back to another file. I would like to know how to use a progress bar to mark the progress of the task.

View Answers

October 30, 2010 at 3:31 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;

public class ProgressBarExample extends JFrame{
    int i=0;
    Timer timer;
    public ProgressBarExample() {

    final JLabel label=new JLabel();
    final JButton button = new JButton("Start");
    final JProgressBar pb = new JProgressBar(0, 20);
        pb.setValue(0);
        pb.setStringPainted(true);
        JPanel panel = new JPanel();
        panel.add(button);
        panel.add(pb);
        JPanel panel1 = new JPanel();
        panel1.add(panel, BorderLayout.NORTH);
        panel1.add(label, BorderLayout.CENTER);
        add(panel1);
        setSize(300,100);
        setVisible(true);

        timer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
        if (i == 20){
          Toolkit.getDefaultToolkit().beep();
          timer.stop();
          button.setEnabled(true);
          pb.setValue(0);
          String str = "<html><font color=red>" + "<b>" + 
"File is readed." + "</b>" + "</font>" + "</html>";
          label.setText(str);
        }
        i = i + 1;
                pb.setValue(i);

            }
        });
        button.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae) {
      button.setEnabled(false);
      int i = 0;
      String str = "<html><font color=green><b>File Reading is in process.......</b></font></html>";
      label.setText(str);
      timer.start();
      try{
                BufferedReader reader = new BufferedReader(new FileReader("c:/data.txt"));
String line=null;

while ((line=reader.readLine())!=null){
String data = line.replaceAll(" ","");
FileWriter fstream = new FileWriter("c:/out.txt",true);
BufferedWriter output = new BufferedWriter(fstream);
output.write(data);
output.newLine();
output.close();
}
                }
                catch(Exception e){}
        }
    });
    }
   public static void main(String[] args) {
        ProgressBarExample spb = new ProgressBarExample();
    }
}

Thanks


October 30, 2010 at 3:33 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;

public class ProgressBarExample extends JFrame{
    int i=0;
    Timer timer;
    public ProgressBarExample() {

    final JLabel label=new JLabel();
    final JButton button = new JButton("Start");
    final JProgressBar pb = new JProgressBar(0, 20);
        pb.setValue(0);
        pb.setStringPainted(true);
        JPanel panel = new JPanel();
        panel.add(button);
        panel.add(pb);
        JPanel panel1 = new JPanel();
        panel1.add(panel, BorderLayout.NORTH);
        panel1.add(label, BorderLayout.CENTER);
        add(panel1);
        setSize(300,100);
        setVisible(true);

        timer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
        if (i == 20){
          Toolkit.getDefaultToolkit().beep();
          timer.stop();
          button.setEnabled(true);
          pb.setValue(0);
          String str = "<html><font color=red>" + "<b>" + 
"File is readed." + "</b>" + "</font>" + "</html>";
          label.setText(str);
        }
        i = i + 1;
                pb.setValue(i);

            }
        });
        button.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae) {
      button.setEnabled(false);
      int i = 0;
      String str = "<html><font color=green><b>File Reading is in process.......</b></font></html>";
      label.setText(str);
      timer.start();
      try{
                BufferedReader reader = new BufferedReader(new FileReader("c:/data.txt"));
String line=null;

while ((line=reader.readLine())!=null){
String data = line.replaceAll(" ","");
FileWriter fstream = new FileWriter("c:/out.txt",true);
BufferedWriter output = new BufferedWriter(fstream);
output.write(data);
output.newLine();
output.close();
}
                }
                catch(Exception e){}
        }
    });
    }
   public static void main(String[] args) {
        ProgressBarExample spb = new ProgressBarExample();
    }
}

Thanks









Related Tutorials/Questions & Answers:
Using Progress Bar in java apps
Using Progress Bar in java apps  Please, i am writing a program in java to read a file, perform some operation on each line of the file and them write back to another file. I would like to know how to use a progress bar to mark
Progress Bar in Java
application. In Java Progress Bar is created using swing. The Swing Class used... Progress Bar in Java      ... in the implementation of Progress Bar in Java. This Program provides you how a Progress Bar
Advertisements
Progress Bar implementation in Java Script
Progress Bar implementation in Java Script  Hi Friend, I am new to Java Script, but i want implement the progress bar in my html by reading... progress bar will show the status. I hope you under stand my issue. Please do
Progress Bar in Java Swing
Progress Bar in Java Swing     ... in java swing. This section shows you how the progress bar starts and stops... the progress bar using it's constructor JProgressBar() to show the status of your
Progress Bar
Progress Bar  Hi friend, I'm interested in knowing how to progress bar in oracle forms 9i for the trigger when-button-pressed.Thankyou. Thanks and Regards, M.SHANKAR
progress bar
progress bar  Hi guys, I'm doing a file upload in spring MVC technology. For file upload i did validation in client side.While uploading how to use an ajax function to show the progress bar
Progress Bar in Java
application. In Java Progress Bar is created using swing. The Swing Class used... Progress Bar in Java      ... in the implementation of Progress Bar in Java. This Program provides you how a Progress Bar
Progress Bar - Swing AWT
Progress Bar  Hey if possible plz help me in making the following program work... i m using threads in order to make the progress bar auto increment..." is for manual updation of progress bar.. import java.awt.*; import javax.swing.
ModuleNotFoundError: No module named 'progress_bar'
ModuleNotFoundError: No module named 'progress_bar'  Hi, My Python... 'progress_bar' How to remove the ModuleNotFoundError: No module named 'progress_bar' error? Thanks   Hi, In your python
Maven dependency for com.chillerlabs - android-circular-progress-bar version 0.0.1 is released. Learn to use android-circular-progress-bar version 0.0.1 in Maven based Java projects
( com.chillerlabs - android-circular-progress-bar version 0.0.1 ) in their Java project...; com.chillerlabs - android-circular-progress-bar version 0.0.1 in Java projects. Follow...-circular-progress-bar version 0.0.1 java library in your project. ADS_TO_REPLACE_2
Dojo Progress Bar
Dojo Progress Bar          In this section, you will learn about the progress bar and how to create a progress bar in dojo. Try Online: Progress BarADS_TO_REPLACE_1
ModuleNotFoundError: No module named 'c_progress_bar'
ModuleNotFoundError: No module named 'c_progress_bar'  Hi, My... named 'c_progress_bar' How to remove the ModuleNotFoundError: No module named 'c_progress_bar' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'c_progress_bar'
ModuleNotFoundError: No module named 'c_progress_bar'  Hi, My... named 'c_progress_bar' How to remove the ModuleNotFoundError: No module named 'c_progress_bar' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyterm-progress-bar'
ModuleNotFoundError: No module named 'pyterm-progress-bar'  Hi, My... named 'pyterm-progress-bar' How to remove the ModuleNotFoundError: No module named 'pyterm-progress-bar' error? Thanks   Hi
ModuleNotFoundError: No module named 'pyterm-progress-bar'
ModuleNotFoundError: No module named 'pyterm-progress-bar'  Hi, My... named 'pyterm-progress-bar' How to remove the ModuleNotFoundError: No module named 'pyterm-progress-bar' error? Thanks   Hi
ModuleNotFoundError: No module named 'snake_progress_bar'
ModuleNotFoundError: No module named 'snake_progress_bar'  Hi, My... named 'snake_progress_bar' How to remove the ModuleNotFoundError: No module named 'snake_progress_bar' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'text_progress_bar'
ModuleNotFoundError: No module named 'text_progress_bar'  Hi, My... named 'text_progress_bar' How to remove the ModuleNotFoundError: No module named 'text_progress_bar' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'text_progress_bar'
ModuleNotFoundError: No module named 'text_progress_bar'  Hi, My... named 'text_progress_bar' How to remove the ModuleNotFoundError: No module named 'text_progress_bar' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'console-progress-bar'
ModuleNotFoundError: No module named 'console-progress-bar'  Hi...: No module named 'console-progress-bar' How to remove the ModuleNotFoundError: No module named 'console-progress-bar' error? Thanks   Hi
ModuleNotFoundError: No module named 'c_progress_bar'
ModuleNotFoundError: No module named 'c_progress_bar'  Hi, My... named 'c_progress_bar' How to remove the ModuleNotFoundError: No module named 'c_progress_bar' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dash-progress-bar'
ModuleNotFoundError: No module named 'dash-progress-bar'  Hi, My... named 'dash-progress-bar' How to remove the ModuleNotFoundError: No module named 'dash-progress-bar' error? Thanks   Hi, In your
Version of com.chillerlabs>android-circular-progress-bar dependency
List of Version of com.chillerlabs>android-circular-progress-bar dependency
Create Progress Bar in SWT
Create Progress Bar in SWT   ... Bar. SWT allows to create a Progress bar by providing the class ProgressBar... the progress in the form of bar. The method setMinimum() sets the minimum value
progress bar in google map - Development process
progress bar in google map   in my google map i want a progress bar... are loaded on the map.  Hi Nikhil, This is simple progress bar code...; private JPanel topPanel; public ProgressBarDemo(){ setTitle("Progress Bar
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for android-circular-progress-bar version 0.0.1
-circular-progress-bar version 0.0.1. You can add these depency in your project to get com.chillerlabs:android-circular-progress-bar:0.0.1 Java library in your... for android-circular-progress-bar version 0.0.1 In this section have given
Maven Dependency android-circular-progress-bar >> 0.0.1
You should include the dependency code given in this page to add Maven Dependency of com.chillerlabs >> android-circular-progress-bar version0.0.1 in your project
Maven Repository/Dependency: com.chillerlabs | android-circular-progress-bar
Maven Repository/Dependency of Group ID com.chillerlabs and Artifact ID android-circular-progress-bar. Latest version of com.chillerlabs:android-circular-progress-bar dependencies. # Version Release Date
Creating custom application download progress bar
the easiest way of creating own download progress bar i.e by using the class... Creating custom application download progress bar  ... will know how to create a customized application download progress bar
Create Scroll Bar in Java using SWT
Create Scroll Bar in Java using SWT       This section is all about creating scroll bar in Java SWT  The given example will show you how to create scroll bar in Java using
Dojo Progress Bar
Dojo Progress Bar      ... the progress bar and how to create a progress bar in dojo. Progress Bar : The progress bar is a GUI (Graphical User Interface) that gives dynamic feedback
Dojo Progress Bar
Dojo Progress Bar      ... the progress bar and how to create a progress bar in dojo. Progress Bar : The progress bar is a GUI (Graphical User Interface) that gives dynamic feedback
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
Bar Chart using JSP and tooltip to be implemented
Bar Chart using JSP and tooltip to be implemented  Hi Deepak, I have generated a bar chart in JSP using JFreeCharts but I could not get the tool tip for that. Please any one suggest me how to do that or provide some code. Help
java bar charts and jsp
java bar charts and jsp  Hi, Can any one help me out in how to create java bar charts using jsp with the help of data base table values? thanks in advance   Have a look at the given link: http://www.roseindia.net
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error...\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57: cannot find symbol
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply...;jspService(bar_jsp.java:80) org.apache.jasper.runtime.HttpJspBase.service...) org.apache.jsp.bar<em>jsp.</em>jspService(bar_jsp.java:57
PHP GD Progress Bar
Stacked Bar Chart using JFreeChart
Stacked Bar Chart using JFreeChart   ... bar chart using JFreeChart. In the code given below we have extended class... of ApplicationFrame class by using super keyword that will be name
Stacked Bar Chart Example using JFreeChart
Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team... class by using super keyword that will be name of the created frame. Some
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score... to the constructor of ApplicationFrame class by using super keyword that will be name
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error...\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:61: cannot
framework in java apps
framework in java apps   com.scooterframework.orm.sqldataexpress.object.RowData how to import the framework got the error in normal import
Create a bar chart in JSP page using JFreeChart
Create a bar chart in JSP page using JFreeChart... to create a bar chart in JSP page using JFreeChart. Code given below creates a bar chart... to the constructor of ApplicationFrame class by using super keyword
Swings Menu Bar - Java Beginners
Swings Menu Bar  Hello, I created a menu bar using Java Swings... n New Record, Edit Record etc are the menu items. Now, I want to display... bar... How to do this..?? or atleast what to use to get this..??  Hi
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match... value to the constructor of ApplicationFrame class by using super keyword
Maven dependency for com.tasomaniac - delayed-progress version 0.4 is released. Learn to use delayed-progress version 0.4 in Maven based Java projects
; com.tasomaniac - delayed-progress version 0.4 in Java projects. Follow the step... and includes  com.tasomaniac - delayed-progress version 0.4 java library...-progress released The developers of   com.tasomaniac - delayed-progress
Maven dependency for avalon-apps - avalon-apps-sevak-jo version 0.1 is released. Learn to use avalon-apps-sevak-jo version 0.1 in Maven based Java projects
-apps - avalon-apps-sevak-jo version 0.1 in Java projects. Follow the step by step tutorial for using the latest version of avalon-apps - avalon-apps-sevak-jo...-apps - avalon-apps-sevak-jo version 0.1 java library in your project. ADS
Maven dependency for avalon-apps - avalon-apps-sevak-api version 0.1 is released. Learn to use avalon-apps-sevak-api version 0.1 in Maven based Java projects
; avalon-apps - avalon-apps-sevak-api version 0.1 in Java projects. Follow the step by step tutorial for using the latest version of avalon-apps - avalon-apps...; avalon-apps - avalon-apps-sevak-api version 0.1 java library in your project
Maven dependency for avalon-apps - avalon-apps-hsql version 0.1 is released. Learn to use avalon-apps-hsql version 0.1 in Maven based Java projects
use this version ( avalon-apps - avalon-apps-hsql version 0.1 ) in their Java...-hsql version 0.1 in Java projects. Follow the step by step tutorial for using...Maven dependency for  avalon-apps  - Version 0.1 of avalon-apps-hsql
AJAX Progress Bar for KUpload+
AJAX Progress Bar for KUpload+      ... information about the current upload, just like pure HTML progress bar but instead of popup window it uses an inline progress bar with the AJAX technology

Ads