progressBar Problem

help me how to make a progress bar

Page 1 of 1

8 Replies - 3933 Views - Last Post: 13 October 2010 - 08:24 PM Rate Topic: -----

#1 mackey19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 10

progressBar Problem

Posted 11 October 2010 - 04:12 AM

can someone help me to make a progress bar in a GUI.
because i don't know how to start it.
I am only a begginer in java that's why i ask it.
i found some tutorial here for how to make a progressbar but i don't know how can i start it.
can you give some pointers to edit it or how to make it..

this is the sample program that i paste for you to easy to help me....
thanks..
i hope someone will help me..
anything will be appriciated...


package project;

import java.awt.Color;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class ProjectView extends FrameView {

    public ProjectView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ProjectApp.getApplication().getMainFrame();
            aboutBox = new ProjectAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ProjectApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        Start = new javax.swing.JButton();
        Exit = new javax.swing.JButton();
        BackGround = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(project.ProjectApp.class).getContext().getResourceMap(ProjectView.class);
        Start.setBackground(resourceMap.getColor("Start.background")); // NOI18N
        Start.setFont(resourceMap.getFont("Start.font")); // NOI18N
        Start.setText(resourceMap.getString("Start.text")); // NOI18N
        Start.setName("Start"); // NOI18N
        Start.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                StartMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                StartMouseExited(evt);
            }
        });
        Start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StartActionPerformed(evt);
            }
        });
        Start.setBounds(80, 210, 150, 30);
        jLayeredPane1.add(Start, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Exit.setBackground(resourceMap.getColor("Exit.background")); // NOI18N
        Exit.setFont(resourceMap.getFont("Exit.font")); // NOI18N
        Exit.setText(resourceMap.getString("Exit.text")); // NOI18N
        Exit.setName("Exit"); // NOI18N
        Exit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                ExitMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                ExitMouseExited(evt);
            }
        });
        Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitActionPerformed(evt);
            }
        });
        Exit.setBounds(240, 210, 150, 30);
        jLayeredPane1.add(Exit, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackGround.setIcon(resourceMap.getIcon("BackGround.icon")); // NOI18N
        BackGround.setText(resourceMap.getString("BackGround.text")); // NOI18N
        BackGround.setName("BackGround"); // NOI18N
        BackGround.setBounds(0, 0, 400, 250);
        jLayeredPane1.add(BackGround, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(project.ProjectApp.class).getContext().getActionMap(ProjectView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>                        

private void StartMouseEntered(java.awt.event.MouseEvent evt) {                                   
// TODO add your handling code here:
    Start.setForeground(Color.BLUE);
}                                  

private void StartMouseExited(java.awt.event.MouseEvent evt) {                                  
// TODO add your handling code here:
    Start.setForeground(Color.BLACK);
}                                 

private void ExitMouseEntered(java.awt.event.MouseEvent evt) {                                  
// TODO add your handling code here:
    Exit.setForeground(Color.BLUE);
}                                 

private void ExitMouseExited(java.awt.event.MouseEvent evt) {                                 
// TODO add your handling code here:
    Exit.setForeground(Color.BLACK);
}                                

private void ExitActionPerformed(java.awt.event.ActionEvent evt) {                                     
// TODO add your handling code here:
    System.exit(0);
}                                    

private void StartActionPerformed(java.awt.event.ActionEvent evt) {                                      
// TODO add your handling code here:
    new menu().setVisible(true);
    ProjectApp.getApplication().getMainFrame().setVisible(false);
}                                     

    // Variables declaration - do not modify                     
    private javax.swing.JLabel BackGround;
    private javax.swing.JButton Exit;
    private javax.swing.JButton Start;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration                   

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
} 







Is This A Good Question/Topic? 0
  • +

Replies To: progressBar Problem

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: progressBar Problem

Posted 11 October 2010 - 04:46 AM

Doing this in a GUI builder is not particularly a good idea, as no human is able to read and debug it and we can't help you on DIC...
Was This Post Helpful? 1
  • +
  • -

#3 mackey19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 10

Re: progressBar Problem

Posted 11 October 2010 - 05:13 AM

it only a sample..
can you tell me some way of making a progress bar?
or some code 2 show my progressbar..
i make some code to proccess it..
its running but the progressbar is still hidden..





Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: progressBar Problem

Posted 11 October 2010 - 08:52 AM

Alright, well there is a good tutorial provided by Sun that I urge you to read:
http://download.orac...s/progress.html

It does involve a bit of threading using SwingWorker, but I'm sure the tutorial will cover it.
Was This Post Helpful? 1
  • +
  • -

#5 mackey19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 10

Re: progressBar Problem

Posted 12 October 2010 - 06:47 AM

thanks for your help..
and also to your advise..





Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: progressBar Problem

Posted 12 October 2010 - 02:15 PM

Glad I could help. :)
Was This Post Helpful? 1
  • +
  • -

#7 mackey19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 10

Re: progressBar Problem

Posted 13 October 2010 - 05:36 AM

can we convert String format to char format??
or char format to String format?
if possible how??




Was This Post Helpful? 0
  • +
  • -

#8 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: progressBar Problem

Posted 13 October 2010 - 11:16 AM

Ok, no need to post non-code in code tags...It's very distracting. If you want a String to be a char[], you can always use the toCharArray() method. And if you want to convert a char[] to a String, you pass it into a String constructor.

char[] chars = string.toCharArray();
String newStr = new String(chars);



If you want to convert a single character from a String, use the charAt(). To do it the other way around, you can either cast it or use the Character.toString() method.

char firstLetter = string.charAt(0);
String aLetter = 'c' + "";
String anotherLetter = Character.toString('v');


Was This Post Helpful? 3
  • +
  • -

#9 mackey19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 10

Re: progressBar Problem

Posted 13 October 2010 - 08:24 PM

thank you very much..
you're so nice..
i can finish now my simple project because of you..

can i want to give you a reputation how?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1