Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Getting rid of deprecation

Options
  • 23-02-2006 4:22pm
    #1
    Registered Users Posts: 1,144 ✭✭✭


    i've been asked to remove the deprecated methods from one of our projects (written in java). I have a query: It says to replace show() and hide() methods with setVisible(true) or setVisible(false). But if hide or show are method declarations in one file, it doesnt let me have 2 setVisible methods in the one java class. Does anyone know how i'd set these methods up so thet dont give me any warnings?

    public void show() //have to replace this with setVisible
    {
    super.setVisible(true);
    }

    public void hide() // Have to also replace this with setVisible
    {
    setVisible(false);
    }
    }


Comments

  • Registered Users Posts: 20,994 ✭✭✭✭Stark


    There's already a setVisible(boolean flag) method in the super class? Then you don't need to do anything other than remove show() and hide() from your implementation.

    PS: If you were to add an option for setVisible(true) or setVisible(false) into your class, then you don't put that in verbatim, you put in setVisible(boolean flag) ;) Otherwise trying to put in a method that accepted something like a decimal value could get very messy :D


  • Closed Accounts Posts: 36 l337


    why would you want 2 setVisible() in one class?
    public void setVisible(boolean b) {
    if (b==true) {
    // stuff
    } else {
    //stuff
    }
    }

    If there is a setVisible() in a superclass you may in fact need to override it in any subclass, depending on what the subclass does eg
    Superclass -> drawHead, superclass.setVisible(false) {//remove head}
    Subvclass -> drawHeadAndShoulders subclass.setVisible(false) {//super.setVisible(false); this.removeShoulders()}


    apologies if this doesn't make any sense


  • Registered Users Posts: 1,144 ✭✭✭gracehopper


    l337 wrote:
    apologies if this doesn't make any sense

    No it does, i've had a look at the sun tutorial and my Net Beans manual i understand now. Cheers for the help and to Stark aswell

    nice one!


Advertisement