Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Getting rid of deprecation

  • 23-02-2006 04:22PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2, Paid Member Posts: 21,262 ✭✭✭✭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, Registered Users 2 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