Results 1 to 2 of 2

Thread: Removing points from a Vector

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2004
    Location
    youngstown, oh
    Posts
    202

    Removing points from a Vector

    Hi, I am still working on the same code, but now I need to add a new feature concering the Vector I was previoulsy asking about.
    My new problem is this :
    I need to click the right button of the mouse and the most recent featur point should be deselected. I want the feature point to be removed from the vector and it's coresponding circle/rectangle erased from the image panel.

    So first thing first removing the point from the Vector. features is the name of my vector.
    I think I would use something like "features.remove". Does it have something like "removeLastElement", or do i need to come up with something else.? Help would be apperaicated.

    i will post my code, soon here some anyone can help. -thanks
    --thanks for the help.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2004
    Location
    youngstown, oh
    Posts
    202

    Re: Removing points from a Vector

    So sorry i took so long, the holiday weekend put me out of commission for a while, but I'm ready to go now.

    Being a novice to Java, I'm having a little trouble folloowing the documentation at Sun. I have been studying the part on Vectors for the time, and I need a little help with the syntax.

    Code:
    if(panelID == 1) {                              
    	         if(e.getButton() == MouseEvent.BUTTON1) {   
                      Point p = new Point(e.getPoint());
                      features.add(p);
                      repaint();
                   }
    	         if(e.getButton() == MouseEvent.BUTTON3) {   // right button, remove features.
                      features.remove (0);
                      repaint();
                   }

    the line " features.remove (0);" removes the first thing in the Vector i Added. What I want to do is remove the last thing i Added to the Vector named features. How am I able to do that. I have tried the same as "add(p);" like "remove(p);" but no luck. is their a special expression I could use to devlop the removal of that last added item of the Vector ?? Thanks for helping- justin.

    Code:
    int nfts = features.size();
          if(nfts == 0)
             return;
    	   if(panelID == 1) 
    	   {    
    		   for(int i = 0; i < nfts; i++)
    		   {
    			   Point p = (Point)features.get(i);
    			   if(p == null)
    				   continue;
    			   g2d.setColor(Color.white);
    			   g2d.setStroke(new BasicStroke(2.0f));
    			   g2d.drawOval(p.x-5, p.y-5, 10, 10);
    		   }
    	   }
    ....this code is just here to show what i do with the points after they are added to the Vector.
    --thanks for the help.

Posting Permissions

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



Click Here to Expand Forum to Full Width