Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Java Practical9

Uploaded by

Priyanka Thadke
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)
3 views

Java Practical9

Uploaded by

Priyanka Thadke
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/ 6

Name:- Priyanka Khandu Thadke

Class:-A(CO5I) Roll no:- 60


Practical no:-09 Write a java to launch a JProgressBar.
Program code:-
Q.1 write a program code to generate the following output.

import javax.swing.*;

public class Pr9 extends JFrame {

JProgressBar jb;

int i = 0, num = 0;

Pr9() {

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) {

Pr9 m = new Pr9();

m.setVisible(true);

m.iterate();

}
}
Output:-

Exercise:-

Q.1 Develop a program to demonstrate the use of JProgressBar.

import javax.swing.*;

public class Pr9 extends JFrame {

JProgressBar jb;

int i = 0, num = 0;

Pr9() {

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) {

Pr9 m = new Pr9();

m.setVisible(true);

m.iterate();

}
}
Output:-
Q.2) Write a program using JProgressBar to show the progress of Progressbar when user click
on JButton.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

class Pr91 extends JFrame implements ActionListener {

JProgressBar pb;

JButton b1 = new JButton("LOGIN");

Pr91() {

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[]) {

Pr91 m = new Pr91();

}
}
Output:-

You might also like