p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_java thread: Re: Variable found in class but not according to the debugger ! !


Message #1 by "Michael \"Nazgul\" C." <nazgul@c...> on Thu, 18 Apr 2002 09:18:48 +0300
Hello!
Of course compiler found variable TEXT in your code since you hardcoded it
yourself :)
But compiler did not find its _declaration_.
Obvious you have declarations for variables such as CIRCLE, CURVE, RECTANGLE
and I think for TEXT too in interface Constants.
Look there for error in declaration of TEXT (or even for missing of
declaration).
GL
Michael

----- Original Message -----
From: <dominskis@a...>
To: "Beginning Java" <beginning_java@p...>
Sent: Thursday, April 18, 2002 1:48 AM
Subject: [beginning_java] Variable found in class but not according to the
debugger ! !


>
> Dear People,
>  I have an error message of:
>
> "SketchView.java": Error #: 300 : variable TEXT not found in class
> sketchercalculator.SketchView.MouseHandler at line 122, column 105
>
> The vaiable is found as one can see from this line of code:
>
> else if(((modifier & e.BUTTON1_MASK)) != (0 && (theApp.getWindow
> ().getElementType() != TEXT)))
>
> Confusing !
> below is the entire method
> Thank you in advance
> Stan


Message #2 by dominskis@a... on Thu, 18 Apr 2002 01:48:26
Dear People,
 I have an error message of:

"SketchView.java": Error #: 300 : variable TEXT not found in class 
sketchercalculator.SketchView.MouseHandler at line 122, column 105

The vaiable is found as one can see from this line of code:

else if(((modifier & e.BUTTON1_MASK)) != (0 && (theApp.getWindow
().getElementType() != TEXT)))

Confusing !
below is the entire method
Thank you in advance
Stan



package sketchercalculator;

//Sketcher Program #12
//has  switch statement  enabling lines,rectangles, circles and curves

import java.awt.*;          //for graphics
import javax.swing.*;
import java.util.*;        //for Observer
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.event.*;   // for mouse input adapter

   class SketchView extends JComponent implements Observer,Constants
    {
       private SketcherCalculator theApp;

      public SketchView(SketcherCalculator theApp)
       {

       this.theApp = theApp;

       //create the mouse listener
       MouseHandler handler = new MouseHandler();

       //Listen for button events
       addMouseListener(handler);

       //Listen for motion events
       addMouseMotionListener(handler);
    }

     //Method called by observable object when it changes
        public void update (Observable o, Object rectangle)
     {
       if(rectangle == null)
        repaint();
        else
          repaint((Rectangle)rectangle);
     }

      public void paint(Graphics g)
       {
         //get a 2D device context
         Graphics2D g2D = (Graphics2D)g;
         Iterator elements = theApp.getModel().getIterator();
         Element element;

         //go through the list
         while(elements.hasNext())
          {
            //get the next element
            element = (Element)elements.next();

            //set the element color
            g2D.setPaint(element.getColor());

            //draw its shape
            g2D.draw(element.getShape());
          }
      }

         class MouseHandler extends MouseInputAdapter
          {
            public void mousePressed(MouseEvent e)
             {
               //save the cursor position
               start = e.getPoint();

                //get modifires
                int modifier = e.getModifiers();

                if((modifier & e.BUTTON1_MASK) != 0)
                 {
                   //get graphics context
                   g2D = (Graphics2D)getGraphics();

                   // set XOR mode
                   g2D.setXORMode(getBackground());

                   //set color
                   g2D.setPaint(theApp.getWindow().getElementColor());

                 }
              }


            public void mouseDragged(MouseEvent e)
             {
               last =   e.getPoint();
               int modifier = e.getModifiers();

               if((modifier & e.BUTTON1_MASK) != 0)
                {
                  //is there an element :
                  if(tempElement == null)
                     //no , so create one
                    tempElement =   createElement(start,last);
                  else
                   {
                     // yes - draw to erase it
                     g2D.draw(tempElement.getShape());

                     //now modify it
                     tempElement.modify(start,last);
                   }
                     //draw it
                     g2D.draw(tempElement.getShape());

                }
              }

                public void mouseReleased(MouseEvent e)
                 {
                  int modifier = e.getModifiers();

                  if(e.isPopupTrigger())
                   {
                     start = e.getPoint();
                     theApp.getWindow().getPopup().show((Component)
e.getSource(), start.x,start.y);
                     start = null;
                   }
                    else if((modifier & e.BUTTON1_MASK) != 0 && 
(theApp.getWindow().getElementType() != TEXT))

                     {

                      if(tempElement != null)
                       {
                         // add element to the model
                         theApp.getModel().add(tempElement);

                         tempElement = null;

                    }

                       if(g2D != null)
                        {
                          g2D.dispose();
                          g2D = null;
                        }
                       //remove the points
                       start = last = null;
                   }
                }


             private Element createElement(Point  start, Point end)
              {
                switch(theApp.getWindow().getElementType())
                 {
                   case LINE:
                     return new Element.Line(start, end, theApp.getWindow
().getElementColor());

                     //version 2 Of Element class and SkecthView 
createElement() method changes...
                     // Take away the comment symbol for case RECTANGLE  
to activate the rectangle coding
                   case RECTANGLE:
                     return new Element.Rectangle(start, end, 
theApp.getWindow().getElementColor());

                     //version 3 Of Element class and SketchView 
createElement() method changes...
                   // take away the comment sysmol for case CIRCLE
                   case CIRCLE:
                     return new Element.Circle(start, end, theApp.getWindow
().getElementColor());

                      //version 4 Of Element class and SketchView 
createElement() method changes...
                   //take away the comment symbol for case CURVE
                   case CURVE:
                     return new Element.Curve(start, end, theApp.getWindow
().getElementColor());
               }
                 return null;
            } //end of class MouseHandler

    //temporary graphics context
    private Graphics2D g2D;

    // Stores cursor     position on press
    private Point start;

    //stores cursor position on drag
    private Point last;

    //stores a temporary element
    private Element tempElement;
 }
}

 

  Return to Index