0% found this document useful (0 votes)
11 views5 pages

AJP9

The document contains Java code examples demonstrating the use of JProgressBar in graphical user interface applications. It includes two practical exercises: one that shows a progress bar incrementing automatically and another that updates the progress bar when a button is clicked. Both examples illustrate the implementation of a JFrame and the use of threading to manage the progress updates.

Uploaded by

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

AJP9

The document contains Java code examples demonstrating the use of JProgressBar in graphical user interface applications. It includes two practical exercises: one that shows a progress bar incrementing automatically and another that updates the progress bar when a button is clicked. Both examples illustrate the implementation of a JFrame and the use of threading to manage the progress updates.

Uploaded by

Sumedh Raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

dd

NAME: SUMEDH SANJAY RAUT


CLASS: CO5I(A)
ROLL NO: 532
SUBJECT: AJP(22517)

 PRATICAL NO :- 9

Q.1 write a program code to generate the following output .

CODE:-

import javax.swing.*;
public class Pract9 extends JFrame {
JProgressBar jb;
int i = 0, num = 0;
Pract9() {
jb = new JProgressBar(0, 2000);
jb.setBounds(40, 40, 160, 30);
jb.setValue(0);
jb.setStringPainted(true);
add(jb);
setSize(250, 150);
setLayout(null);
}
public void iterate() {
while (i <= 2000) {
jb.setValue(i);
i = i + 20;
try {
Thread.sleep(150);
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
Pract9 m = new Pract9();
m.setVisible(true);
m.iterate();
}
}
dd

OUTPUT:-

Exercise:-

Q.1 Develop a program to demonstrate the use of JProgress Bar.


Code:-
import javax.swing.*;
public class Pract9Ex extends JFrame {
JProgressBar jb;
int i = 0, num = 0;
Pract9Ex() {
jb = new JProgressBar(0, 2000);
jb.setBounds(40, 40, 160, 30);
jb.setValue(0);
jb.setStringPainted(true);
add(jb);
setSize(250, 150);
setLayout(null);
}
public void iterate()
{ while (i <=
2000)
dd

{ jb.setValue(
i); i = i + 20;
try {
Thread.sleep(150);
} catch (Exception e) {
}
}
}
public static void main(String[] args)
{ Pract9Ex m = new Pract9Ex();
m.setVisible(true);
m.iterate();
}
}

Output:-

Q.2) Write a program using JProgressBar to show the progress of Progressbar


when
User Click on JButton.

Code:-
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class Pract09 extends JFrame implements ActionListener {
JProgressBar pb;
dd

JButton b1 = new JButton("LOGIN");


Pract09() {
setLayout(null);
setSize(330, 100);
setVisible(true);
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, 200, 25);
pb.setValue(i);
i++;
}
} catch (Exception e1) {
System.out.print("Caughted exception is =" + e1);
}
}
}
public static void main(String arg[]) {
Pract09 m = new Pract09();
}
}
public static void main(String arg[]) {
Pract09 m = new Pract09();
}
}

Output:-
dd

You might also like