Inheritance tree and interfaces

Hello!
Interface is not a part of inheritance tree. It means, that the next code is absolutely legal:
class App{
       public static void main(String... args){
                Bar bar = (Bar)new Foo();
class Foo{}
interface Bar{}You can compile it, run and get a ClassCastException.
But if I write it so:
final class Foo{}
...I'll get compilation error.
I know how it works, but I don't understand why.
Does anybody have any ideas?

Ataraxisme++.
Cue JLS :
JLS sayz (emphasis added):
5.1.6 Narrowing Reference Conversions
The following conversions are called the narrowing reference conversions :
❋ From any reference type S to any reference type T, provided that S is a proper supertype (§4.10) of T. (An important special case is that there is a
narrowing conversion from the class type Object to any other reference type.)
❋ From any class type C to any non-parameterized interface type K, provided that C is not final and does not implement K.
❋ From any interface type J to any non-parameterized class type C that is not final.
❋ From the interface types Cloneable and java.io.Serializable to any array type T[].
❋ From any interface type J to any non-parameterized interface type K, provided that J is not a subinterface of K.
❋ From any array type SC[] to any array type TC[], provided that SC and TC are reference types and there is a narrowing conversion from SC to TC.
Such conversions require a test at run time to find out whether the actual reference value is a legitimate value of the new type. If not, then a ClassCastException is thrown.

Similar Messages

  • No list tree of device and interface, software in MAX sytem. using pci 6034E and chasis 2345

    Hye, i got the problem about this device.
    I using PCI 6034 E which will connect to SCC 2345 to measure current and voltage.
    My os is 32 bit Windows XP.
    First i install this software, my MAX listed the tree of devices & interface which is PCI 6034 E and chasis 2345, and all download software are listed in tree of software.
    By the way, when i start to measure the current, my MAX is working fine.. but, the problem is starting in the next day, wheni try to measure againt, all the list are dissapear. Then i uninstall all the NI component and reinstall again. Thereare a lot of install and reinstall again and again.. By the way the result is still same. Do not have any tree appear..
    so, any colution for my problem?
    i try to solve this problem, and i read that when the tree of devices and interfaces not appear, it's maybe because we using driver : NI 488.2 , i try to uninstall this driver.. by the way the result is still same...

    sahizansalman,
    It looks like the same is happening with the Software list. This is often a sign of a MAX database corruption. I'd try the steps outlined in this knowledgebase: 
    What is the Process For Removing MAX Database Corruption?
    Feel free to post back if this does not work. 
    By the way, do you know what device is showing up as unknown in the device manager? You did not mention anything besides your PCI DAQ card and SCC 2345, which are showing up fine. 
    Message Edited by mishkin on 03-11-2010 07:42 AM
    Misha

  • Missing Devices and Interfaces in Conviguration tree in MAX

    I trying to configure our instruments in MAX, however devices and interfaces is missing from the configuration tree.  How can I fix this?

    Hi Nem,
    Thanks for the reply and I hope your well today.
    Ah ok, your trying to communicate with an instrument and LabVIEW. That is fine, so firstly I would suggest looking for a LabVIEW 'Driver' or LabVIEW VI library where the programming has already been done for you. Looking at ni.com/idnet I coudln't find a driver for the MW100.
    Do you have VIs already? Or are you looking to program from the beginning? If so - do you have a programmer guide to the MW100?
    Generally, though, to see the device in MAX you'll need the NI-Driver which handles the connectivity to the device.. this in general is NI-VISA, which can be downloaded at ni.com/downloads.  This handles GPIB/Serial/USB. However, we have more specific GPIB functions in LabVIEW which are installed with NI-488.2, and for Serial NI-Serial. I would advise installing the respective one also. (To confirm you'll need VISA to see the device in MAX).
    A great guide for the process you need to follow can be found here,
    Instrument Control Fundamentals: Instrument Control Software
    http://zone.ni.com/devzone/cda/tut/p/id/4357
    Please let me know your thoughts, 
    Kind Regards
    James Hillman
    Applications Engineer 2008 to 2009 National Instruments UK & Ireland
    Loughborough University UK - 2006 to 2011
    Remember Kudos those who help!

  • Enumerate multiple inheritance scenarios and their java equivalents?

    hi,
    ppl have often said things like
    "java doesn't support multiple inheritance but this is ok, since there are other mechanisms for doing the same thing (by which we nearly always mean interfaces)"
    how solid a statement is this? are there any formal methods available eg smt like "over all possible inheritance trees over all possible classes, only a handful of cases are distinct when viewed from the converting-to-single-inheritance scheme"?
    the two things mentioned as harder to workaround are mixins and the diamond problem - are there more?
    also what other mechanism apart from interfaces (if any) are useful?
    any help appreciated,
    asjf

    What I say is that it doesn't matter since there is
    almost never any need for MI. Most of the time it is
    used it is used because the developer/designer did not
    understand what they were doing and it should not have
    been used in the first place.
    That leaves one with very few cases where it should
    ever be used. And that coupled with the fact that a
    developer should never use it unless they are very
    experienced (so that they actually know that it should
    be used,) means that practicing programmers should
    leave discussion of such usages to scholarly
    journals.thanks :) I guess my problem is that often with computer stuff you don't have to rely on other peoples experience about things - you can go and test it yourself
    I've done very little C++ development, and so have never come across real-world multiple inheritance. I bumped into the first situation with some java code where it might've been a neat solution recently but this could easily fit into the "designer did not understand what they were doing" category from above..
    will have a casual look around the scholarly journals if I can find any that look promising :)
    asjf

  • Spanning Tree and Admin mac address issues srw2048

    Ok, I have a somewhat complex problem and hopefully someone may shed some light or have an idea as to whats wrong.
    First the scenario:
    I have two Cisco Cat 6509's etherchanneled to each other via two fiber cables.  One of these is the STP/RSTP root.  I have two SRW2048's.. one trunked to each of these 6509 switches.  There is also a trunk between the SRW2048's.  All this is to create a redundant topology so that if one of the switches fail's the others can still forward packets to each other.  Of course the scenario described is in fact a loop that should be handled by STP/RSTP.  I have RSTP enabled on all the switches in the scenario (PV RSTP on the cisco switches as they only do Cisco's brand of per vlan spanning tree).  There are 3 vlan's configured on each of the srw2048's (2,55,96).  There are corresponding vlan's also on the 6509's.  I have put the srw2048's management interface into vlan 2.
    The problem:
    I need to forward packets between the srw2048's primarily and only use the 6509 that is not the root when a failure happens.  I have configured the non-root 6509's spanning tree cost on the etherchannel to be higher then the alternate path through the srw's to the root.  I can hook everything up and view the spanning tree and see that the srw2048's interface that goes to the non-root 6509 is blocked, and all other interfaces on the other switches are forwarding.  I can in fact ping and get to the admin interface on all the switches.  Then for some strange reason the admin interface of the srw2048 plugged into the non-root 6509 stops responding.  If I disable either the interface its plugged into on the 6509 or the other srw2048 everything starts working again.  Sometimes it responds after many failures for no apparent reason.  I looked into the mac-address table on the 6509's and they are conflicting, pointing to each other for the mac-address of the broken srw2048.  When I clear the mac-table the admin port comes back for about 5 seconds then again goes dark.  When reviewing mac-table on the 6509's they are back to pointing to each other.  The odd thing (although I haven't confirmed this completely) is that hosts placed into vlan 2 on that same srw2048 seem to work fine.  If there was an STP loop or something misconfigured, I would expect it to effect any host in vlan 2 or the other vlan's for that matter on the srw2048 that stops responding.  Alas, I am stuck because I need to manage this switch remotely.  My only thought is that for some reason even when the STP status is blocked the broken srw2048 is still sending out arp's of its admin interface and bypassing the STP protocol.  I have no way to confirm this, but maybe someone has an idea as to what I'm doing wrong, or otherwise offer a solution.  For now, I simply removed vlan 2 from the 6509 that the broken srw2048 is plugged into and everything seems fine.
    My apologies for such a long post, but this is somewhat complicated.  Thanks in advance for any info.
    -Geoff
    Message Edited by gmyers on 08-19-2008 10:35 PM

    To follow up, I had a ticket open with Linksys about this for about 3 months with no resolution.  I submitted packet captures, stp outputs, etc and no luck.  I gave up and basically had to revert to a manual failover for redundancy.  It's no perfect or fast, but it works every time.
    Unless linksys issues a firmware upgrade with this as a fix, I doubt we will be able to ever resolve this on our own.

  • Multiple inheritance in remote interfaces for EJB 3.0 session beans on Webl

    Hi All,
    We started migration from EJB 2.1(WLS 8.1) to EJB 3.0(WLS 10.3.2) and identified few serious problems. One of them is related with multiple business interfaces inheritance. I wrote simple example that presents point of the problem.
    we have session bean AImpl:
    +@Stateless(name="A")+
    +@Remote({A.class})+
    +@TransactionAttribute(TransactionAttributeType.REQUIRED)+
    +public class AImpl implements A {+
    +@Override+
    +public void writeA() {+
    System.out.println("A");
    +}+
    +@Override+
    +public void writeB() {+
    System.out.println("B");
    +}+
    +@Override+
    +public void writeC() {+
    System.out.println("C");
    +}+
    +}+
    with remote interface A:
    +@Remote+
    +@JNDIName(A.JNDI_NAME)+
    +public interface A extends B, C {+
    public static String JNDI_NAME = "A_JNDI_NAME";
    void writeA();
    +}+
    As you can see A extends B, and C. Definition of both interfaces is very simple:
    +public interface B {+
    void writeB();
    +}+
    +public interface C {+
    void writeC();
    +}+
    Everything looks nice until we want to invoke some method on AImpl bean. For above implementation code:
    A a = ctx.lookup(A. JNDI_NAME);
    a.writeA();
    a.writeB();
    a.writeC();
    writes down ”A \n B” and throws exception:
    caused by: java.lang.NoSuchMethodException: pl.gov.arimr.zszik.bazowe.slowniki.ejb.A_vt0zts_AImpl_1032_WLStub.*writeC()*
    at java.lang.Class.getMethod(Class.java:1605)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.getTargetMethod(RemoteBusinessIntfProxy.java:165)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:57)
    so.. in stub generated by WLS there is no method from interface C ! What more interesting after small change in interface A rely on change in interface implementation order from B, C to C, B (+public interface A extends C, B {+) server writes down only A and I have stack like below:
    Caused by: java.lang.NoSuchMethodException: pl.gov.arimr.zszik.bazowe.slowniki.ejb.A_vt0zts_AImpl_1032_WLStub.*writeB()*
    at java.lang.Class.getMethod(Class.java:1605)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.getTargetMethod(RemoteBusinessIntfProxy.java:165)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:57)
    After this experience I came up with suspicion that Weblogic 10.3 does not support inheritance from multiple interfaces in one “generation”. Instead of that it takes only the first interface from the list.
    Does anybody have some experience with such a situation? maybe someone have an idea how to work around this problem?

    This is Not Supported in WebLogic that the Remote Interface extends other Interfaces. Because Annotation Processor just looks up inside the implemented interface methods. The actual interface which is Implemented by the Bean Class. So the Methods declared inside the Interface B and Interface C will be ignored and will not be available as part of the generated Stubs. Thats why u are getting NoSuchMethodError.
    You can even contact Oracle Support on this...there are 3-4 Cases on it. And the Solution is Work As Designed.
    Workaround is : edit your interface A as following
    Declare all the Business Methods only in the Remote Interface and not inside it's Super Interfaces.
    Example:
    @Stateless(name="A")
    @Remote({A.class})
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public class AImpl implements A {
    @Override
    public void writeA() {
    System.out.println("A");
    @Override
    public void writeB() {
    System.out.println("B");
    @Override
    public void writeC() {
    System.out.println("C");
    @Remote
    @JNDIName(A.JNDI_NAME)
    public interface A extends B, C {
    public static String JNDI_NAME = "A_JNDI_NAME";
    void writeA();
    void writeB();
    void writeC();
    Thanks
    Jay SenSharma
    http://jaysensharma.wordpress.com (WebLogic Wonders Are Here)

  • [svn:fx-trunk] 10459: Change to ensure ScriptNodes are no longer part of the node tree after interface compilation stage in order to avoid the extra code that was necessary to avoid tripping over them during type checking , etc.

    Revision: 10459
    Author:   [email protected]
    Date:     2009-09-21 08:42:44 -0700 (Mon, 21 Sep 2009)
    Log Message:
    Change to ensure ScriptNodes are no longer part of the node tree after interface compilation stage in order to avoid the extra code that was necessary to avoid tripping over them during type checking, etc.
    Improving revision 10199 a bit, to allow for single line comments.
    QE notes: None
    Doc notes: None
    Bugs: SDK-22027
    Reviewer: Paul
    Tests run: Checking, Compiler cyclones
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22027
    Modified Paths:
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/AbstractSyntaxTreeUtil.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/InterfaceCompiler.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/builder/AbstractBuilder.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/builder/DocumentBuilder.java

    In general theory, one now has the Edit button for their posts, until someone/anyone Replies to it. I've had Edit available for weeks, as opposed to the old forum's ~ 30 mins.
    That, however, is in theory. I've posted, and immediately seen something that needed editing, only to find NO Replies, yet the Edit button is no longer available, only seconds later. Still, in that same thread, I'd have the Edit button from older posts, to which there had also been no Replies even after several days/weeks. Found one that had to be over a month old, and Edit was still there.
    Do not know the why/how of this behavior. At first, I thought that maybe there WAS a Reply, that "ate" my Edit button, but had not Refreshed on my screen. Refresh still showed no Replies, just no Edit either. In those cases, I just Reply and mention the [Edit].
    Also, it seems that the buttons get very scrambled at times, and Refresh does not always clear that up. I end up clicking where I "think" the right button should be and hope for the best. Seems that when the buttons do bunch up they can appear at random around the page, often three atop one another, and maybe one way the heck out in left-field.
    While I'm on a role, it would be nice to be able to switch between Flattened and Threaded Views on the fly. Each has a use, and having to go to Options and then come back down to the thread is a very slow process. Jive is probably incapable of this, but I can dream.
    Hunt

  • No Devices and Interface in MAX

    Hi all,
    I recently installed the evaluation version of LabVIEW and I am trying to communicate with a Mark-10 Series 5 force gauge. The problem, however, is that MAX does not seem to detect the instrument or any other instrument. There isn't even a Device and Interface tree.
    I am running Windows 7 and the Mark-10 drivers are installed (and is detected by the device manager as a USB device).
    Anyone have any idea what could be wrong?
    Solved!
    Go to Solution.

    I recently went through this problem. You have to register a USB instrument to use the VISA driver. There is an NI tutuorial on how to do this. You can find the tutorial here.
    This allows 3rd party instruments to show in MAX and be used in LabVIEW.
    Rob

  • Use of events and interface in class

    Dear All,
    Could you please explain why we use events and interface in class.
    Also please tell me the use of TRY and ENDTRY.
    Regards,
    Amar

    Events may be a way of communication b/w classes. Imagine you want to call certain code from one class, you would need for that public method, but you don't want to expose it to external user. So you may use events for that. Also events are used to notify that certain state of class has changed (tiggering event). Then all handlers of this event executes and react accordingly.
    Interfaces are a way of provide a service to class which implements it. Imagine that you have class office and hotel and gas station . They don't seems to have something in common. However, there can be some external energy provider which will be an interface. Each class which want to have a lease with this energy provided can implement it (the implementation can differ in some way), so he can provided energy to different classes. This way you will achieve polimorphism (meaning you call one interface method, but code behind it differs from class to class).
    Interfaces are also means of multiple inheritance. One class can implement several service (interfaces). In contrary it can oly inherit from one class.
    Try endtry are just new way of handling exceptions .
    Try to search a litte bit you will find lots of info on the above.
    Regards
    Marcin

  • Abstract classes and Interfaces

    Why would you use these? Why not make a concrete class and extend them? I see why JAVA doesn't use mutiple inheritance but I don't see how allowing interfaces correctes that, after all what happens if two interfaces implemented by one class have two fully defined methods with the same signature but differant outputs?
    I tryed googleing this but just got articles on when to use Abstract over interface and interface over abstract, which should have helped some but it didn't.
    Can someone explain or post a link for a good example.

    Why would you use these? Why not make a concrete
    class and extend them? Check out the JDBC interfac (java.sql package).
    The core Java API defines what types and methods it wants to use for DB interactions. But because every DB and driver is so different, there's no concrete implementation that the core API could provide for those types. It's up to the vendors to provide all the "how"--all the concrete implementations of the methods.
    interfaces correctes that, after all what happens if
    two interfaces implemented by one class have two
    fully defined methods with the same signature but
    differant outputs?That rarely happens (it has never happened to me in about 8 years of Java programming) and if it does, you just have to find a different approach--you can't meet both contracts.

  • About Classes and Interfaces

    How can we define the classes and interfaces in an interview can u give me any realtime example for this

    How can we define the classes and interfaces in an
    interviewThe easiest explanation probably is to say that an interface in Java is a special class, namely a totally abstract one, that has been given a separate name.
    Classes and interfaces (because they're classes in disguise) both constitute types, meaning that variables can be declared of them. The difference is that a class can carry implementation whereas an interface cannot (because it's totally abstract).
    Java has single inheritance of implementation which means the the inheritance of classes is restricted to exactly one while you can inherit as many interfaces you like.

  • Doubt in inheritance tree..!

    hi SAP Guru's !
    here is My example :
    Class c1 definition.
    endclass.
    Class c2 definition INHERITING FROM c1.
    endclass..
    Class c3 definition INHERITING FROM c2.
    endclass.
    Out of these which one is the root node of inheritance tree  ?
       and
    what is the meaning of this (empty class object )
    " the root node on all inheritance trees in ABAP Objects is the predefined EMPTY class OBJECT. "

    Hello Rajesh
    The root of all classes in ABAP is the class OBJECT.
    Think about an itab in which you want to store instances of any kind of class. What kind of linet_type do you use for your itab?
    If, for example, all your collected instances are sub-classes of your c1 class (or c1 itself) then you could use your class C1 as line_type.
    If the collected instances do not belong to a single inheritance tree then you must use class OBJECT as line_type.
    Example: Have a look at the iterator class CL_SWF_UTL_ITERATOR and its attribute MT_OBJECT_LIST where any kind of instances can be collected.
    Further examples of how to use the iterator class or class OBJECT are:
    Storing and retrieving objects from an internal table
    [Accessing the Inacessible - Local Classes within Global Classes|https://wiki.sdn.sap.com/wiki/display/ABAP/AccessingtheInacessible-LocalClasseswithinGlobalClasses]
    Regards
      Uwe

  • Method access$0() and Interfaces doubts

    Hello All,
    I am working on a class browser, I have created one and it works successfully to a certain extent. But The class which I am having a Demo for a Tree Implementation in GUI, has a method called access$0() which I guess is automatically created on runtime by the super classes or somewhere, please let me know how and where can I get more details about this method.
    Also If my class under inspection is implementing one or more interfaces, how can I access its method names and variables.
    Also One more question, does Java maintain a list of sub-class information for each class somewhere.. just like Small Talk or it doesn't?? Please explain.
    Thanks,
    Sirish

    access$ methods are widely used to access private
    members of enclosing class from its inner class and
    vice-versa. These methods are generated by Java
    compiler, not by JVM runtime.
    See
    http://java.sun.com/docs/books/jvms/second_edition/htm
    l/ClassFile.doc.html#80128 for more details about
    synthetic class members.
    Other questions need more clarification.I will check that link, Regarding the other two questions:
    2. What I meant in my interfaces question is that... Say I have a class X that Extends Y and implements A,B
    Then if I want to display all the methods and fields of these classes and interfaces in a recursive way, till I reach the Object class, by going to superclass every time, then I understand I can get to class Y simple by
    using x.getSuperClass()
    but how can I get the interface methods?? and go upwards in that hierarchy??
    3. Sub class question is like this - Say I have 3 classes all user defined in the same directory Class A,B,C where A is the superclass of B and C. My class browser is displaying the hierarchy details of A, then is there any way to put in the details of B and C in the same hierarchical display or just display a separate list of subclass that this class has. I am not sure whether I have made it clear still.
    (I didnot understnad your reply on changing the class path, can you please explain it in a bit more detail, provided it holds for this question.)
    Regards,
    Sirish

  • Inheritance, components and paintComponent - what am I doing wrong ?

    Hi people,
    I've created a component that inherits from JPanel and contains a JLabel and a DisplayJAI (component from JAI, which is used to display images, and which also is derived from JPanel). My component is called DisplayJAIWithInformation, and its methods are as follow:
    // bunch of imports
    public class DisplayJAIWithPixelInformation extends JPanel implements MouseMotionListener
      /** The component used to display images */
      protected DisplayJAI dj;
      /** The label used to display information about the image */ 
      protected JLabel label;
      // some more fields
      public DisplayJAIWithPixelInformation(RenderedImage image)
        // create instances and set the user interface (layout, add   
        // components, register event listeners
      public void mouseDragged(MouseEvent e)
        // does nothing but keeps the MouseMotionListener interface happy
      public void mouseMoved(MouseEvent me)
        // gets the coords, get the pixel info and set the text on
        // the label
        } // end of method mouseMoved
    Full code not posted to avoid making this post too long to be useful, but I can post the full code if needed, it is not an industrial secret :-)
    It works without problems.
    Now I want to create an inherited class which will have the same funcionality but will also draw some stuff on the displayed image.
    From what I understood, I should create the inherited class and overwrite its paintComponent method. Here it is:
    // bunch of imports
    public class DisplayJAIWithROIs extends DisplayJAIWithPixelInformation
      private PlanarImage image; // the image which will be passed to the super
      public DisplayJAIWithROIs(RenderedImage image)
        super(image);
        this.image = image; // a local reference
      public void paintComponent(Graphics g)
        // HERE - what should I do ?
        Graphics2D g2d = (Graphics2D)g;
        // g2d.fill using some shapes in color and using transparency
        // through AlphaComposite
      }Again, code is not complete for brevity, will post all if anyone needs it (the code is going to a web site anyway, there is already some stuff on http://www.geoambiente.com.br/~rafael/JAI).
    I'm stuck on what should I write on the paintComponent of the inherited (descendent?) class. Here's what I've tried:
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g;
    // draw stuffThis causes the image to be drawn with the shapes but there is a gray haze over it. When I scroll the image (it has a JScrollable wrapper around the instance of DisplayJAIWithROIs) the repaint is horrible, with parts missing.
    I've figured that I want to draw over the DisplayJAI instance on the super class, therefore tried
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)dj.getGraphics();
    // draw stuffAll is drawn correctly the first time, but when I move the mouse over the image, the transparent shapes become less transparent as I move the mouse, making the shapes filled with 1.0 opacity.
    All I want to do is use a class and draw upon one component of it which is declared as protected, but I'm lost. I could, of course, redesign the classes but will have to replicate several things. Any suggestion ?
    thanks
    Rafael

    Hi and thanks again,
    In your DisplayJAIWithROIs
    paintComponent method you could start with
    g2.drawImage(..image..) and then follow with the rest
    of your drawing code. OK - with that I would overload the paintComponent of the superclass so it won't be called, but if the paintComponent of the superclass contains more complex behaviour I would have to cut and paste it into the paintComponent of my derived class - couldn't do it for classes which I have no access to the source code :-(
    I'd
    recommend you try some small test programs (as above)
    for this. OK, here is a simple code that does not uses JAI and reproduces the problem. If you have some time, please look into it.
    The first class is the "image", except I created a large enough component which inherits from JPanel, like the component (DisplayJAI, http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/widget/DisplayJAI.html)
    I do not have access to the DisplayJAI class, and would suppose its paintComponent to be rather complex.
    package display;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    public class MyBigComponent extends JPanel
      public MyBigComponent()
        super();   
      public Dimension getPreferredSize()
        return new Dimension(1000,1000); 
      public Dimension getMinimumSize()
        return getPreferredSize(); 
      public Dimension getMaximumSize()
        return getPreferredSize(); 
      public void paintComponent(Graphics g)
        super.paintComponent(g);
        g.drawLine(0,0,999,999);   
      } The second class is the combined component I wrote (a label and an instance of the class above):
    package display;
    import java.awt.BorderLayout;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    public class MyDisplayComponent extends JPanel
      protected JLabel label;
      protected MyBigComponent component;
      public MyDisplayComponent()
        setLayout(new BorderLayout());
        component = new MyBigComponent();
        add(new JScrollPane(component),BorderLayout.CENTER);
        label = new JLabel("info goes here");
        add(label,BorderLayout.SOUTH);
      }This class works OK, but has no paintComponent - I guess it is not required to have one.
    The third class extends the second one since I want to draw more stuff on the "image" but not touch the label.
    package display;
    import java.awt.Color;
    import java.awt.Graphics;
    public class MyNewDisplayComponent extends MyDisplayComponent
      public MyNewDisplayComponent()
        super();     
      // with no PaintComponent: paints the MyBigComponent, the red rect does not appear
      public void paintComponent0(Graphics g)   
        System.out.println("repainting mynewdisplaycomponent");
        super.paintComponent(g);
        Graphics g2 = super.component.getGraphics();   
        g2.setColor(Color.RED);   
        g2.drawRect(10,10,210,210); 
        // paints the MyBigComponent, paints the red rect, which disappears   
        // almost immediately
      public void paintComponent1(Graphics g)   
        System.out.println("repainting mynewdisplaycomponent");
        super.component.paintComponent(g);   
        g.setColor(Color.RED);   
        g.drawRect(10,10,210,210); 
        // paints the MyBigComponent, the red rect does not appear
      public void paintComponent2(Graphics g)   
        System.out.println("repainting mynewdisplaycomponent");
        super.paintComponent(g);   
        g.setColor(Color.RED);   
        g.drawRect(10,10,210,210); 
        // paints the MyBigComponent, the red rect does not appear
      }The class above have three versions of the paintComponent - I've tried those three versions (which were renamed to paintComponent when used, one by one). The last comment on each method tells the results - either I got nothing drawn or the red rectangle disappeared soon.
    The last class is just the starting point of the application:
    package display;
    import javax.swing.JFrame;
    public class MyApp
      public static void main(String[] args)
         JFrame frame = new JFrame();
         frame.getContentPane().add(new MyNewDisplayComponent());
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setSize(500,500);
         frame.show();  
      }If you have any suggestion, please advise. The basic idea is to be able to paint on a component contained in other component.
    thanks again
    Rafael

  • Difference between abstract classes and interfaces

    I actually wonder about what are the differences between abstract classes and interfaces may somebody give an example code about it?
    and i have one more question how can i use interfaces like multiple inheritance ? i mean when i implement an interface like
    class a extends b implements c,di have to use all c and d methods but what that methods means?
    I mean as i know we cannot make implementations of methods in interfaces
    but for example in runnable interface there is a method like run() and it has been defined somewhere because it knows what to do(i mean when it will run), i just write my code into that method .

    Once you get past the starting point (I am referring to the OP here), there are a few salient differences:
    You can only extend (or generalize) a single superclass; however, you can implement (or realize) multiple interfaces. As such, all things being equal, using an interface in lieu of an abstract class 'frees' your design. Later, if you want the implementor of an interface to inherit from another class, there is not issue.
    Any abstract method specifies a contract. However, abstract classes allow you to also add common behavior to subclasses. This is an overused justification for abstract classes, IMO. You can achieve the same effect using delegation and still having interfaces.
    Always program to interfaces wherever possible. This means that you define an interface and have an implementing class (usually at a minimum). Do not do this for all your classes, but rather the ones that make your system unique (the domain model or M in MVC architecture). This allows you to later change implementation with a minimal amount of refactoring. This is a core precept from the Group of Four and any number of decent programming books.Best of luck.
    - Saish

Maybe you are looking for

  • Question regarding encryption and decryption

    Hi all, I am doing a authentication project. In which I do encryption and decryption (AES 128 bit) in two different methods. At the time of encryption (for eg a text file ), I store the key in dat file (key.dat). And at the time of decryption, I read

  • USB OTG function doesn't work on Z30STA100-6/10.3.1.2243

    Like the title says, USB OTG doesn't work on my Z30 STA100-6 running the latest official OS 10.3.1.2243. It worked before on 10.2.1.3062. I did tried basic troubleshooting procedures like turning the device OFF then ON, reformat my flash drives to FA

  • Where to keep the jar files

    I have some common classes that I want use across the SWCV/namespaces/Mappings. What is the best place to import. 1. In Imported archives of  each name space for each swcv 2.  Create a shared name space in each SWCV and place in this swcv under impor

  • Select and where clause

    Hi I want to write a select statement and in where condition 1.I want to retrieve the fields which contains a string 'ABAP' 2.I want to retreive the fields which is equal to space. eg; SELECT FLD1 FLD2 FLD3 FROM TABLE1 WHERE    WHERE    fld1 contains

  • Check in Original Manadatory

    Hi All, I have a problem with originals check in. How to make the check in originals Mandatory for a document on the system?(when we create a document in CV01N) because at present for some reason the original doesn't get saved properly so i need to c