Mistake in the Braces
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Mistake in the Braces

  1. #1
    Join Date
    Jun 2008
    Posts
    32

    Mistake in the Braces

    Copied this from the Oracle docs on Swingworker

    Code:
    class PrimeNumbersTask extends 
             SwingWorker<List<Integer>, Integer> {
         PrimeNumbersTask(JTextArea textArea, int numbersToFind) { 
             //initialize 
         }
    
         @Override
         public List<Integer> doInBackground() {
             while (! enough && ! isCancelled()) {
                     number = nextPrimeNumber();
                     publish(number);
                     setProgress(100 * numbers.size() / numbersToFind);
                 }
             }
             return numbers;
         }
    
    
    
         @Override
         protected void process(List<Integer> chunks) {
             for (int number : chunks) {
                 textArea.append(number + "\n");
             }
         }
     }
    
     JTextArea textArea = new JTextArea();
     final JProgressBar progressBar = new JProgressBar(0, 100);
     PrimeNumbersTask task = new PrimeNumbersTask(textArea, N);
     task.addPropertyChangeListener(
         new PropertyChangeListener() {
             public  void propertyChange(PropertyChangeEvent evt) {
                 if ("progress".equals(evt.getPropertyName())) {
                     progressBar.setValue((Integer)evt.getNewValue());
                 }
             }
         });
    
     task.execute();
     System.out.println(task.get()); //prints all prime numbers we have got

    Is there a mistake in the braces or am I missing something? The discrepancy is replicated on other pages with the same example...

  2. #2
    Join Date
    Aug 2005
    Posts
    198

    Re: Mistake in the Braces

    Yes - the 'doInBackground' method has an extra closing brace. The 'while' loop is being closed twice.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center