Results 1 to 3 of 3
  1. #1
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default reference to linked list

    How to set a new polygon as the same with one of the existing triangles in linked list?

    Java Code:
    java.util.List<Polygon> triangles = new LinkedList<Polygon>();
    
    polygon triangle, selectedtriangle;
    
    Point startDrag,endDrag, midPoint;
    ....
    
    triangles.add( new Polygon(xs, ys,3)); 
    .....
    
    public void mousePressed(MouseEvent e) {
    ....
      startDrag = new Point(e.getX(), e.getY());  
      endDrag   = startDrag;
    
      //check if mouse pressed inside existing polygon triangle
      for (Polygon p : triangles) { 
        if (p.contains(startDrag)) {//inside triangle 
    
           //This doenst seem right code.
           selectedTriangle = triangles.indexOf(p.contains(startDrag)); 
           break; //
        }
      }
    .....
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Does it compile?
    The answer is "no" since selectedTriangle is a polygon (by the way, classes should start with a capital letter), and indexOf() returns an int.
    I assume you want to set selectedTriangle to the one that's been clicked on, so just assign it:

    Java Code:
    selectedTriangle = p;
    If you're having problems with such a basic concept then maybe you ought to take a step back and work through the sun tutorials?

  3. #3
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

Similar Threads

  1. Linked list
    By rosh72851 in forum New To Java
    Replies: 1
    Last Post: 02-05-2009, 07:21 AM
  2. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  3. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 03:15 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 03:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:29 AM

Posting Permissions

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