/* Program : 8 Create an application that will demonstrate the concept of ProgressBar. Developed by : Malhar Vora Developed on : 9-11-2010 Development Status : Completed and tested Email : vbmade2000@gmail.com WebSite : www.malhar2010.blogspot.com *******************************************************************************************************************/ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class P8 extends JFrame implements ActionListener { JProgressBar pBar=null; JButton btnStart=null; JButton btnStop=null; MakeProgress mp=null; boolean stop=false; P8() { //Setting properties of Frame setSize(400,200); setResizable(false); setTitle("Progressbar Demo"); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); this.getContentPane().setLayout(null); pBar = new JProgressBar(0,100); pBar.setBounds(10,10,360,40); pBar.setStringPainted(true); btnStart = new JButton("Start"); btnStop = new JButton("Stop"); btnStart.setBounds(10,80,100,50); btnStop.setBounds(120,80,100,50); this.getContentPane().add(pBar); this.getContentPane().add(btnStart); this.getContentPane().add(btnStop); btnStart.addActionListener(this); btnStop.addActionListener(this); //makeProgress(); mp = new MakeProgress(); } public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); if(cmd.equals("Start")) { stop=false; } else if(cmd.equals("Stop")) { stop=true; } } class MakeProgress extends Thread { MakeProgress() { start(); } public void run() { while(true) { if(stop==true) { try{ wait(); } catch(Exception e) { ; } } else { if(pBar.getValue()==100) { pBar.setValue(0); } pBar.setValue(pBar.getValue()+1); pBar.setString("" + pBar.getValue()); try{ sleep(2000); } catch(InterruptedException ie){ ; } } } } } public static void main(String []str) { P8 p = new P8(); } }
Friday, November 12, 2010
Create an application that will demonstrate the concept of ProgressBar.
Labels:
Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.