Results 1 to 5 of 5
  1. #1
    man4ish is offline Member
    Join Date
    Dec 2009
    Posts
    14
    Rep Power
    0

    Default How to extend two classes

    Hi,

    I am working on swing. I am going to extend two classes
    1. JPanel
    2. JFrame

    import javax.swing.JFrame;
    import javax.swing.*;

    /**
    *
    * @author manish
    */
    public class Main extends JFrame, JPanel
    {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    }

    }


    but this is not allowed in java. May i know how this can be implemented? Thanks in advance.

    Thanks
    Manish

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    What are you trying to achieve?
    What kind of object is both a JFrame and a JPanel?

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    in java, class can only extends 1 and only 1 superclass

    calss A extends JFrame,
    class B extends JPanel

    in class A, use class B object(?) or override JPanel object directly(?)

  4. #4
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    if you only need methods then Interfaces are your friends ;-)
    look into super classes and learn wich interfaces they implement
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by man4ish View Post
    Hi,
    I am working on swing. I am going to extend two classes
    1. JPanel
    2. JFrame
    You've gotten good advice so far, and hopefully mine will be up to snuff, but I'm going to tell you that you rarely need to extend JPanel and almost never need to extend JFrame. What you want to do instead is to extend your classes via composition rather than inheritance (Look up "has-a" vs "is-a" relationship). In other words have your classes hold JFrame and JPanel objects and use them.

    Much luck.

Similar Threads

  1. Extend Jscroll
    By cowboy in forum New To Java
    Replies: 10
    Last Post: 12-13-2009, 08:07 PM
  2. Trying to extend class
    By ribbs2521 in forum New To Java
    Replies: 4
    Last Post: 10-29-2009, 06:28 PM
  3. How can I extend java.net.URI - why is it final?
    By johann_p in forum Advanced Java
    Replies: 1
    Last Post: 08-21-2009, 05:31 AM
  4. extend a button
    By Omarero in forum New To Java
    Replies: 0
    Last Post: 03-25-2009, 06:57 PM
  5. using J-classes or extend them ?
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 01-01-2009, 07:58 PM

Posting Permissions

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