java

java

Saturday 10 December 2011

java program

Class JProgressBar
java.lang.Object
extended byjava.awt.Component
extended byjava.awt.Container
extended byjavax.swing.JComponent
extended byjavax.swing.JProgressBar


public class JProgressBar extends JComponent implements SwingConstants, Accessible

A component that, by default, displays an integer value within a bounded interval. A progress bar typically communicates the progress of some work by displaying its percentage of completion and possibly a textual display of this percentage.

To indicate that a task of unknown length is executing, you can put a progress bar into indeterminate mode. While the bar is in indeterminate mode, it animates constantly to show that work is occurring. As soon as you can determine the task's length and amount of progress, you should update the progress bar's value and switch it back to determinate mode.

Here is an example of creating a progress bar, where task is an object that returns information about the progress of some work:

progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(0);
progressBar.setStringPainted(true);

Here is an example of updating the value of the progress bar:

progressBar.setValue(task.getCurrent());

Here is an example of putting a progress bar into indeterminate mode, and then switching back to determinate mode once the length of the task is known:

progressBar = new JProgressBar();
...//when the task of (initially) unknown length begins:
progressBar.setIndeterminate(true);
...//do some work; get length of task...
progressBar.setMaximum(newLength);
progressBar.setValue(newValue);
progressBar.setIndeterminate(false);





/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author akhtar
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class ProgressBarr extends JFrame implements ActionListener
{
JButton jb;
JProgressBar jpb1;
int value =0;
ProgressBarr()
{
Container contentPane=getContentPane();
contentPane.setLayout(new FlowLayout());

jb = new JButton("Click");
contentPane.add(jb);
jb.addActionListener(this);

jpb1 = new JProgressBar(0,1000);
contentPane.add(jpb1);
jpb1.setStringPainted(true);
}

public static void main(String args[])
{
ProgressBarr pb1 = new ProgressBarr();
pb1.setSize(500,500);
pb1.setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
while(value<=1000)
{
value = value+10;
jpb1.setValue(value);
}
}
}

No comments:

Post a Comment