Results 1 to 6 of 6
  1. #1
    jzyling is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default How to call getElementAt() method in new class definition?

    Hi, I defined:

    public class FLabel extends GLabel implements Runnable{
    //constructor
    public FLable(......){
    ..........
    }

    public void run(){
    .......
    }
    }

    How can I call getElementAt() method in this definition? Thanks a lot!!!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default Re: How to call getElementAt() method in new class definition?

    The way you call any method: get a reference to an instance of the class with the method and use it:

    referenceToClass.theMethodToCall(<args here>);

    You need to be more specific with the details of your code to get a more specific answer.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jzyling is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to call getElementAt() method in new class definition?

    Thank you for your answer. Here are my codes:

    public class FLabel extends GLabel implements Runnable{

    public FLabel(String s,GRect rect){

    super(s);
    this.s=s;
    this.rect=rect;

    setColor(Color.red);
    setFont("TIMES-PLAIN-20");
    }

    public void run(){
    while (true){
    pause(15);
    move(0,STEP);
    if(getElementAt(getX()+getWidth()/2+1,getY())==rect) break;

    }
    }
    private static final double STEP=1.0;
    private String s;
    private GRect rect;
    }

    How to change the bold line? Thank you.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default Re: How to call getElementAt() method in new class definition?

    What do you want to change it to? Can you explain what the problem is?

    If you are getting compiler errors, please copy and paste here the full text of the error message.


    What class and packages are you using? I don't recognize many of the methods and classes you are using.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jzyling is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to call getElementAt() method in new class definition?

    I use acm.jar package.

    I think I solved this problem. I added one Gcanvas instance like canvas to it, then I can call canvas.getElementAt() method.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default Re: How to call getElementAt() method in new class definition?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Inner class method call
    By d915172 in forum New To Java
    Replies: 3
    Last Post: 11-11-2010, 09:40 PM
  2. Trying to call a method from sub class
    By TheNewGuy in forum New To Java
    Replies: 4
    Last Post: 10-17-2010, 07:08 AM
  3. Replies: 2
    Last Post: 05-01-2010, 08:59 AM
  4. How to call a method from another class?
    By jboy in forum New To Java
    Replies: 8
    Last Post: 09-09-2009, 07:29 AM
  5. How to call a class within a method
    By Manfizy in forum New To Java
    Replies: 3
    Last Post: 03-19-2009, 12:34 PM

Tags for this Thread

Posting Permissions

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