Exp 9-1
Exp 9-1
Exp 9-1
X. Program Code
1. Write a program code to generate the following output.
Code
import javax.swing.*;
import java.awt.*;
public class X1 {
public static void main(String[] args) {
JFrame frame = new JFrame("Progress Bar");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 100);
frame.add(progressBar, BorderLayout.CENTER);
frame.setVisible(true);
}
}
XIII. Exercise
1. Develop a program to demonstrate the use of JProgressBar.
Code
import javax.swing.*;
import java.awt.*;
// Create a JProgressBar
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(50);
progressBar.setStringPainted(true);
// Add the progress bar to the frame
add(progressBar, BorderLayout.CENTER);
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public XIII2() {
// Create the frame
setTitle("JProgressBar with Button Example");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// Create a JProgressBar
progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
// Create a JButton
startButton = new JButton("Start");