0% found this document useful (0 votes)
12 views3 pages

Output

AJP practice no 9

Uploaded by

mayasatpute39
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)
12 views3 pages

Output

AJP practice no 9

Uploaded by

mayasatpute39
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/ 3

import javax.swing.

*;
import java.awt.*;
import javax.swing.border.EmptyBorder;

public class ProgressBarExample {


public static void main(String[] args) {
JFrame frame = new JFrame("Progress Bar Example");
frame.setSize(300, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());

JProgressBar progressBar = new JProgressBar(0, 100);


progressBar.setValue(100);
progressBar.setStringPainted(true);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(new EmptyBorder(20, 20, 20, 20));
panel.add(progressBar, BorderLayout.CENTER);
frame.add(panel, BorderLayout.CENTER);
frame.setVisible(true);
}
}

Output :
Exercise No1 :
import javax.swing.*;
import java.awt.*;

public class ProgressBarExample {

public static void main(String[] args) {


JFrame frame = new JFrame("JProgressBar Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 150);
JProgressBar progressBar = new JProgressBar();
progressBar.setMinimum(0);
progressBar.setMaximum(100);
progressBar.setValue(75);
progressBar.setStringPainted(true);
frame.add(progressBar, BorderLayout.CENTER);
frame.setVisible(true);
}
}

Output :
Exercise No 2 :
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SimpleProgressBarExample {


public static void main(String[] args) {
JFrame frame = new JFrame("Simple Progress Bar Example");
frame.setSize(300, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());

JProgressBar progressBar = new JProgressBar(0, 100);


progressBar.setStringPainted(true);

JButton button = new JButton("Start Progress");

button.addActionListener(new ActionListener() {
private int progress = 0;

@Override
public void actionPerformed(ActionEvent e) {
if (progress < 100) {
progress += 10;
progressBar.setValue(progress);
}
}
});
frame.add(progressBar, BorderLayout.CENTER);
frame.add(button, BorderLayout.SOUTH);

frame.setLocationRelativeTo(null);

frame.setVisible(true);
}
}

Output :

You might also like