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

    Mistake in the Braces

    Copied this from the Oracle docs on Swingworker

    class PrimeNumbersTask extends 
             SwingWorker<List<Integer>, Integer> {
         PrimeNumbersTask(JTextArea textArea, int numbersToFind) { 
         public List<Integer> doInBackground() {
             while (! enough && ! isCancelled()) {
                     number = nextPrimeNumber();
                     setProgress(100 * numbers.size() / numbersToFind);
             return numbers;
         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);
         new PropertyChangeListener() {
             public  void propertyChange(PropertyChangeEvent evt) {
                 if ("progress".equals(evt.getPropertyName())) {
     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

    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
    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)