100% found this document useful (1 vote)
722 views5 pages

Practical No - 9

The document provides code for two Java programs that use JProgressBars. The first program continuously updates a JProgressBar from 0 to 2000 over 10 seconds. The second program launches a JProgressBar when a JButton is clicked, also updating it from 0 to 2000 over 10 seconds.

Uploaded by

Pratiksha Jadhav
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
100% found this document useful (1 vote)
722 views5 pages

Practical No - 9

The document provides code for two Java programs that use JProgressBars. The first program continuously updates a JProgressBar from 0 to 2000 over 10 seconds. The second program launches a JProgressBar when a JButton is clicked, also updating it from 0 to 2000 over 10 seconds.

Uploaded by

Pratiksha Jadhav
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

PRACTICAL 9

WRITE A PROGRAM TO LAUNCH A JPROGRESSBAR

1) WRITE A PROGRAM TO DEMONSTRATE THE FOLLOWING OUTPUT:

import javax.swing.*;
import java.awt.*;
public class JProgresBarDemo
{
JProgressBar JProgressBarObj;
int i=0,num=0;
JProgresBarDemo()
{
JFrame JFrameMain = new JFrame();
JFrameMain.setVisible(true);
JFrameMain.setSize(400,400);
JFrameMain.setLayout(new FlowLayout());
JProgressBarObj = new JProgressBar(0,2000);
JProgressBarObj.setValue(0);
JProgressBarObj.setStringPainted(true);
JFrameMain.add(JProgressBarObj);
}
public static void main(String[] args)
{
JProgresBarDemo jpd = new JProgresBarDemo();
jpd.iterate();
}
public void iterate()
{
while(i<=2000){
JProgressBarObj.setValue(i);
i =i+20;
try
{
Thread.sleep(150);
}
catch(Exception e)
{
}
}
}
}

2) Write a Program using JProgressBar to show the progress of


Progressbar when user clicks on JButton.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JProgressBarApplet extends JApplet implements
ActionListener
{
JProgressBar JProgressBarObj;
JButton JButtonObj;
int i=0;
public void init()
{
setSize(400,400);
setVisible(true);
setLayout(new FlowLayout());
JButtonObj = new JButton("Click Me");
JButtonObj.addActionListener(this);
JProgressBarObj = new JProgressBar();
JProgressBarObj.setStringPainted(true);
JProgressBarObj.setValue(0);
add(JButtonObj);
add(JProgressBarObj);
}
public void actionPerformed(ActionEvent ie)
{
this.iterate();
}
public void iterate()
{
while(i<=2000)
{
JProgressBarObj.setValue(i);
i=i+20;
try
{
Thread.sleep(150);
}
catch(Exception e)
{}
}
}
}
/* <applet code="JProgressBarApplet" height="400" width="400">
</applet>
*/
Output:

You might also like