0% found this document useful (0 votes)
177 views10 pages

37 Afzal Khan Ajp Exp 9

The document describes a Java program that uses a JProgressBar to display progress. It creates a JProgressBar object and adds it to a JFrame. It then iterates from 0 to 100, increasing the progress bar's value by 5 each iteration and sleeping for 500 milliseconds to simulate progress. This displays a progress bar that gradually fills up from empty to full over time.

Uploaded by

tanmay ghorai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views10 pages

37 Afzal Khan Ajp Exp 9

The document describes a Java program that uses a JProgressBar to display progress. It creates a JProgressBar object and adds it to a JFrame. It then iterates from 0 to 100, increasing the progress bar's value by 5 each iteration and sleeping for 500 milliseconds to simulate progress. This displays a progress bar that gradually fills up from empty to full over time.

Uploaded by

tanmay ghorai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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