0% found this document useful (0 votes)
24 views

Jprogress

This document describes a Java program that uses a Swing progress bar. It creates a JFrame containing a JProgressBar, JLabel, and start button. When the button is clicked, a Timer is started that increments the progress bar value every 1000 milliseconds until it reaches 20. The label text updates to show the download status. When complete, it beeps and resets the progress bar and label text to indicate download completion.
Copyright
© Attribution Non-Commercial (BY-NC)
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)
24 views

Jprogress

This document describes a Java program that uses a Swing progress bar. It creates a JFrame containing a JProgressBar, JLabel, and start button. When the button is clicked, a Timer is started that increments the progress bar value every 1000 milliseconds until it reaches 20. The label text updates to show the download status. When complete, it beeps and resets the progress bar and label text to indicate download completion.
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

import import import import

java.awt.*; java.awt.event.*; javax.swing.*; javax.swing.text.html.*;

public class SwingProgressBar{ final static int interval = 1000; int i; JLabel label; JProgressBar pb; Timer timer; JButton button; public SwingProgressBar() { JFrame frame = new JFrame("Swing Progress Bar"); button = new JButton("Start"); button.addActionListener(new ButtonListener()); pb = new JProgressBar(0, 20); pb.setValue(0); pb.setStringPainted(true); label = new JLabel("Roseindia.net"); JPanel panel = new JPanel(); panel.add(button); panel.add(pb); JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout()); panel1.add(panel, BorderLayout.NORTH); panel1.add(label, BorderLayout.CENTER); panel1.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); frame.setContentPane(panel1); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create a timer. timer = new Timer(interval, new ActionListener() { public void actionPerformed(ActionEvent evt) { if (i == 20){ Toolkit.getDefaultToolkit().beep(); timer.stop(); button.setEnabled(true); pb.setValue(0); String str = "<html>" + "<font color=\"#FF0000\">" + "<b>" + "Downloading completed." + "</b>" + "</font>" + "</html>"; label.setText(str); }

i = i + 1; pb.setValue(i); } }); } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent ae) { button.setEnabled(false); i = 0; String str = "<html>" + "<font color=\"#008000\">" + "<b>" + "Downloading is in process......." + "</b>" + "</font>" + "</html>"; label.setText(str); timer.start(); } } public static void main(String[] args) { SwingProgressBar spb = new SwingProgressBar(); } }

You might also like