Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Using Progress Bar in java apps
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Samuel A.
Using Progress Bar in java apps
2 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


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.


Advertisement
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 this section, you can learn how to handle progress bar in java swing. This section shows you how the progress bar starts and stops
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
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 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.
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 Bar Progress Bar
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
Creating custom application download progress bar
of creating own download progress bar i.e by using the class DownloadProgressBar... Creating custom application download progress bar  ... will know how to create a customized application download progress bar
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
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
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 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
How to remove virtual keypad from apps java
How to remove virtual keypad from apps java  I have an galaxy smart s6830 touch Chinese Mobile (240x320) (myriad java platform) (esmertec jbed) and I need to remove keypad from apps . I have put the following into the jar file
How to remove virtual keypad from apps java
How to remove virtual keypad from apps java  I have an galaxy smart s6830 touch Chinese Mobile (240x320) (myriad java platform) (esmertec jbed) and I need to remove keypad from apps . I have put the following into the jar file
How to remove virtual keypad from apps java
How to remove virtual keypad from apps java  I have an galaxy smart s6830 touch Chinese Mobile (240x320) (myriad java platform) (esmertec jbed) and I need to remove keypad from apps . I have put the following into the jar file
Free Java Apps for cell phones
Free Java Apps for cell phones       Here you will find free java apps for cell phones and other mobile...; There many apps available these days, commercial applications as well as free java apps
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
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... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57
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
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
Apps
Apps Roseindia Technologies are working on several iPhone apps including several utilities iPhone tools. Some of the apps like BMI calculator and Simple... Inc. while some of the apps have been sent to Apple Inc for approval
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
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
 

 

 

DMCA.com