Sleep(long millis):
It uses to causes the current executing thread to sleep milliseconds specified by a user.It throws interuppted exception and it takes milliseconds as a input parameter.
CODING:
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class tab extends JFrame
{
JProgressBar jp;
tab()
{
setTitle("Progress Bar ");
setLayout(new FlowLayout());
setSize(900,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jp = new JProgressBar();
jp.setStringPainted(true);
add(jp);
for(int i=0;i<=100;i+=1)
{
try{
Thread.sleep(100);
}
catch(InterruptedException ie)
{}
jp.setValue(i);
}
jp.setString("Done");
}
}
class progress {
public static void main(String[] args)
{
tab x = new tab();
}
}
No comments:
Post a Comment