You are on page 1of 10

Input:

import java.awt.*;
import javax.swing.*;
public class Exp9X_1 extends JFrame{
JProgressBar pb;
Exp9X_1(String s){
super(s);
setVisible(true);
setLayout(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
);
setSize(450,450);
pb=new JProgressBar(0,100);
pb.setStringPainted(true);
pb.setValue(0);
pb.setBounds(150,200,200,30);
add(pb);
}
void iterate(){
int i=0;
while(i<=100){
i+=5;
pb.setValue(i);
try{
Thread.sleep(500);
}
catch(Exception e){

}
}
public static void main(String args[])
Exp9X_1 p=new Exp9X_1();
p.iterate(); } }
Output:
Input:
import java.awt.*;
import javax.swing.*;
public class PbDemo extends JFrame{
JProgressBar pb;
PbDemo(String s){
super(s);
setVisible(true);
setLayout(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
);
setSize(490,490);
pb=new
JProgressBar(SwingConstants.HORIZONTAL,0,100);
pb.setStringPainted(true);
pb.setValue(0);
pb.setBounds(150,200,200,30);
add(pb);
}
void iterate(){
int i=0;
while(i<=100){
i+=5;
pb.setValue(i);
try{
Thread.sleep(500);
}
catch(Exception e){
}
}
}
public static void main(String[] args){
PbDemo p=new PbDemo(“Afzal
khan-37”)

p.iterate();
}
}

Output:
Input:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

class PbAction extends JFrame implements ActionListener {


JProgressBar pb;
JButton b1 = new JButton("CLICK!!");

PbAction() {
setLayout(null);
pb = new JProgressBar(1, 100);
pb.setValue(0);
pb.setStringPainted(true);
b1.setBounds(20, 20, 80, 25);
pb.setBounds(110, 20, 200, 25);
pb.setVisible(false);
add(b1);
add(pb);
b1.addActionListener(this);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
int i = 0;
if (e.getSource() == b1) {
pb.setVisible(true);
try {
while (i <= 100) {
Thread.sleep(50);
pb.paintImmediately(0, 0, 210, 26);
pb.setValue(i);
i++;
}
} catch (Exception e1) {
}
}
}
public static void main(String arg[]) {
PbAction m = new PbAction();
m.setSize(500, 500);
m.setTitle("Afzal khan-37");
m.setVisible(true);
}
}

Output:

You might also like