How to make a class confirm to a specific abstract structure?

I have a class which should extend one of the swing component and on the other hand implement an interface. i.e.
public class A extends JTable implements UpdateData
In some other class
public class UpdatePanel extends JPanel
public void setUpdateComp(JComponent anJc)
updateCompJc = anJc;
// but here i want to use methods of interface UpdateData
// which i cannot be sure of that anJc implements those methods since
// its an instance of JComponent.
// One sol in my mind is to cast with UpdateData and check for
// ClassCastException.
// Is there any other way of doing this such that i don't have to cast
// between JComponent and check ClassCastException to be sure that it
// implements reqd. interface
Thanks and reagrds,
Amit.

Hi,
if you use the declaration
public void setUpdateComp(UpdateData anJc) { ..... }
instead, then only an instance of a class can be passed to that method, that has UpdateData implemented - but, you are then restricted to the methods of the interface - if you want to use others, you have to check for the instanceOf this parameter and cast it to that class afterwards.
greetings Marsian

Similar Messages

  • How to make a class an array

    Hello, i am very confused as to how to make an array inside a class and use it from another class. For example, when making a "Book of hotties" where i would create entries in a book(objects) of hot women ,with parameters
    name, last name, phone number, and rating, and i am supposed to make a class for the book itself with a Person [ ] blackBook, and also a separete class called Person where i would create each person. How would i go about creating this array and where would i create it? and from that how can i access it in order to perform methods like sorting and checking entries? Tnx in advance.
    Edited by: Secmugen on May 5, 2009 6:19 AM
    Edited by: Secmugen on May 5, 2009 6:20 AM

    You probably need to start here: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
    There is also a Java collection called ArrayList which is suitable for storing and retreiving objects such as BlackBook, Person etc...
    To access elements of an array within a class you would most likely use a public getter method. eg.
    public class BlackBook {
       private ArrayList<Person> persons = new ArrayList<Person>();
      public ArrayList<Person> getPersons() {
         return this.persons;
      public Person getPerson(int index) {
        this.persons.get(index);
    };etc..

  • How to make a class immutable?

    I hav attend the interview where they ask this question.
    I know little bit is Make the class final and declare all variables as static final .
    Can any Help me.
    This question

    Thi is just my opinion;
    An immutable object is an object that once created, it's values can no longer be changed.
    Thus an immutable object could be an object that allows it's values to be changed only when created with the use of the constructor, and only has get methods to retrieve those values (no set methods).
    @Peetzore
    Defining them as final is something I never did, however it makes sense :) and will start doing so as well
    Regards,
    Sim085

  • How to make standard class as mandatory in eupiment master[class overview]

    Hi,
    In equipment master if I want to make standard class as mandatory field [Check standard class].
    If any any configuration is available please give me the path.
    Else Any user exist is available please suggest me.
    Reward points are available
    Thanks in advance.
    Hanamanta

    hi,
    Just follow the menu path given.
    Cross-Application Components > Classification System >
    Classes > Maintain Object Types and Class Types
    Assign required class type to table EQUI and remove the class types which are not required.
    This will definitely solve ur problem.
    with regards,

  • How to make Singleton Class secure

    I have a Singleton class which I instantiate using reflection by a call to a public getInstance method that return the object from a private constructor. I have to use reflection as I dont have any other options since my class instantiation is decided on runtime. How will I secure other form instantiating the same class again by using reflection on my private constructor? Any ideas?

    How much do these different implementations of your singleton have in common? What I'm getting at is, is there some common code you could extract out of them all, and make that a singleton in it's own right? Needing to do this sort of hacking is often a sign you're fudging something together, that could be solved more elegantly. We use the Singleton pattern generally when the state of the object needs to exist exactly once. Can you extract that from the disparate objects?
    The singleton classes that I load do not have anything in common. They are all similar but unique, and independant in their own respect. I will have to decide only on what singleton object I have to load in runtime, based on certain criterion. This is done by reflection, by a call to the public getInstance() method of the respective singleton classes, since I am deciding on runtime. My problem is that can I prevent others from accessing my private constructor from outside the class using reflection, which enables them to create another duplicate object. Can I restrict them to use only my getInstance() method instead?? I know this is hacking to access the private members, but I want to know whether there is any way where I can restrict this hacking???In the above code I dont want these statements to work at any case
    java.lang.reflect.Constructor[] c = cl.getDeclaredConstructors();
    c[0].setAccessible(true);
    A anotherA  = (A) c[0].newInstance(new Object[]{"Duplicate"});

  • How to make a class serializable

     

    This is not a good place to learn general Java ... I suggest looking at the
    Java serialization specification from JDK1.1 (?) and understanding how
    serialization works.
    It is impossible to answer your question either 'yes' or 'no' ... by saying
    'implements serializable' it does make instances of the class serializable,
    but that does not mean that serialization will work on those instances, for
    example because the instance may have non-null non-transient fields that are
    not serializable. Further more, some of the state may not be appropriate for
    serialization (like a JDBC Connection reference ...).
    Peace,
    Cameron Purdy
    Tangosol Inc.
    << Tangosol Server: How Weblogic applications are customized >>
    << Download now from http://www.tangosol.com/download.jsp >>
    "zille9" <sdsd> wrote in message news:3bf6f272$[email protected]..
    can i make a simple java class serializable by just writing implementsserializable in its implemetation

  • How to make asset class as chart of depreciation dependent

    Hello sap Experts
    we have a requirement from business user where they want that we make an asset class as chart of depreciation DEPENDENT.
    please suggest how to do this & what is the impact of it.
    Thanks & Reagrds
    Deepak Garg

    Dear,
    Deepak.
    You can lock the asset classed as per COD from t.code AM05 or one more you can lock the asset classes from OAOA.
    Go to OAOA select your said asset class see Lock Status area there you can see option Asset class is blocked Tick it. 
    If you need any further clarification please revert back.
    Regards,
    Pankaj Bhalerao.
    Edited by: pankaj_ab on Dec 7, 2009 9:50 AM

  • How to make Outlook 2010 confirm exit?

    I often have a bunch of e-mail windows open with items that need to be followed up on. Sometimes I click the Outlook "X" exit button instead of closing an email by accident, and all those mail items are closed. Sure I can open outlook back up, but which
    of my 50 email items from today were the important ones? Arg. 
    How do I make Outlook prompt "Are you sure?" when the exit button is clicked?
    Thanks!

    Hi,
    Thanks for using Office IT professionals forum. I will forward this suggestion to product group and hope they can improve this in next version.
    Now, You can try to use an addin for this called OLKeeper.
    See http://addins.howto-outlook.com/vboffice_olkeeper
    In addition, if you are using POP3/IMAP email account, you can try this method:
    Create a new message without an address in the To field and save to Drafts then drag it to the Outbox. Then when you exit Outlook, you will get a warning.
    Hope it helps.

  • How to make exit class unicode complaint

    Hi Experts,
    I am trying to make class of category 'Exit class' unicode complaint as it shows me error message as "The program "ZCL_EX_DEF_STP_GATEWAY========CP" is not     
         Unicode-compatible, according to its program attributes."
    But in properties section whenever I try to check unicode flag it shows message as
    "Exit classes/interfaces can only be edited using the BADI Builder".It do not allow.
    Is there any way to make it unicode complaint?

    hi Yogesh,
    Try to use SE18 and see if there is any option for this.
    Regards,
    Vivek

  • How to make application class be an entry in TBRF100 in BRF?

    Hi all
      I am new to BRF .
      I want to know how to create a sample application in BRF.
      I did  all step in the followed link
      http://help.sap.com/saphelp_erp2004/helpdata/en/49/0f2541a2d5b167e10000000a155106/content.htm
      But while doing the last step called   Making Application Data Available to the BRF.
       I am getting an error called
       Input values must be defined in Table TBRF100. The value or values
       'ZBRFAP '(It's my application class) are not specified in this table.
       If any body knows how to resolve this problem please give me your valuable answer.
       Please suggest me some examples on BRF like how to frame rules and events in BRF.
    Regards
    K.S.L.Neelima

    Hi, .Neelima
    plPls. follow the customizing steps in the IMG for the BRF, i.e.:
    spro -> Contract Accounts Receivable and Payable ->  Business Transactions -> Public Sector Tax Assesment-> Busines Rule Framework (BRF) ->  Create Client-Independent Application Class  and the following tasks .
    Define Additional Settings for Application Class, etc.
    Kind regards

  • How to make a class object  from a string representation of the same

    i have the name of a class whose object i want to make in the form of a string i.e. String s="S1"; i get this name after some prosessing. so what i want to do is to create an object of S1 which is actually one class that i have implemented.plz hlp. it is urgent.thnx in advance.

    reflection api...
    see java.lang.Class. Read the api docs.
    mostly, u need to do the following:
    Class myClass = Class.forName(s1);
    Object x = myClass.newInstance();
    reg
    s giri

  • JMS: how to make child class loader (classes) available to parent loader

    Hi,
    Environment: oc4j 10.1.3.1 on SunOS 5.10
    Our application (set up in an instance other than "home") sets up a JMS receiver, everything works fine to the point where the receiver receives the message but the message deserialization fails with the below error. Looks like the deserializer (loaded by the parent classloader sytem.root) is not able to load the class from its child code-source (one of my application libraries in WEB-INF/lib) I have seen a lot of documentation on how libraries can be shared between applications, but I haven't come across any that is related to my problem here. I have even tried adding the library in question to bootclasspath that did not help either.
    How to get around this problem.
    Thanks in advance.
    Caused by: java.io.InvalidClassException: toSerializable
    at com.evermind.server.jms.JMSUtils.toSerializable(JMSUtils.java:1374)
    at com.evermind.server.jms.JMSUtils.toSerializable(JMSUtils.java:1395)
    at com.evermind.server.jms.EvermindObjectMessage.getObject(EvermindObjectMessage.java:114)
    ... 4 more
    Caused by: oracle.classloader.util.AnnotatedClassNotFoundException:
    Missing class: com.deploy.atao.message.client.Message
    Dependent class: com.evermind.io.ClassLoaderObjectInputStream
    Loader: oc4j:10.1.3
    Code-Source: /export/home/oracle10as/product/10.1.3.1/OracleAS_3/j2ee/home/lib/oc4j-internal.jar
    Configuration: <code-source> in META-INF/boot.xml in /export/home/oracle10as/product/10.1.3.1/OracleAS_3/j2ee/
    home/oc4j.jar
    This load was initiated at system.root:0.0.0 using the Class.forName() method.
    The missing class is available from the following locations:
    ......( WEB-INF/lib/ directory in /export/home/oracle10as/product/10.1.3.1/OracleAS_3/j2ee/CI11TRY2/ap
    plications/dev/ci/WEB-INF/lib)
    This code-source is available in loader dev.web.ci:0.0.0. This is a child of the dependent loader system.root:0.0.0.
    at oracle.classloader.PolicyClassLoader.handleClassNotFound(PolicyClassLoader.java:2078)
    at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1679)
    at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1635)
    at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1620)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:219)
    at com.evermind.server.ApplicationContextClassLoader.findClass(ApplicationContextClassLoader.java:23)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:219)
    at com.evermind.io.ClassLoaderObjectInputStream.resolveClass(ClassLoaderObjectInputStream.java:33)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1513)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:322)
    at com.evermind.server.jms.JMSUtils.toSerializable(JMSUtils.java:1364)
    ... 6 more

    Resolved by adding the application library in question to config/application.xml as <library path="<relative path to the library>"/> so the library has instance scope is accessible by the sytem.root loader.

  • How to make the class files to run in a particular platform only

    Class files which are created from the java files should only run on a particular platform only..say i'm going to create the class files for windows environment then those class files should only run on that environment only. it should not run on unix environment etc..how to do this..

    hi,
    i cant think of a reason why you would do something like that.. You cant prevent your class files to be read by the JVM of a different OS, but anyway you could do something to stop your code from running in a different OS, for eg.
    Properties prop = System.getProperties();
    if (prop.getProperty("os.name").startsWith("Windows")==true)
          //code
    else
           System.out.println("Sorry i will not run in this OS");
    }cheerz
    ynkrish

  • How to make Object class to be serializable?

    I'm writing a session bean which contains an Object[][] as a return e.g
    public Object[][] getFoo(){
    I need the return to be of type Object since I'm constracting a 2D array of different object types e.g Integer, Double, HashMap, String etc. But EJBs require serializable objects for their public remote methods. Could you please advice me whether there is another class that I could use instead of the Object class to be serializable? I'm still using SDK1.3.1.
    Thank you

    I've already tried that before, but it doesn't work. When I try to assign different objects to my array as in the following example:
    ABC[][] abc = new ABC[4][2];
    abc[0][0] = new Integer(1);
    abc[0][1] = new String("abc");
    abc[0][2] = new HashMap();
    I'm getting compilation error since Integer, String and HashMap can not be casted into ABC. My question is whether there is such a class (part of the SDK) which implements Serializable AND these classes can be casted to, as in the above example?

  • How to make the filter panel non-folder specific in Bridge CS6

    It seems that the filter panel is folder specific. You click on a folder and only some filters pop up depending on what folder you are looking at and what info is in the photos (I don't know if this refers to tags or not). Assuming I am right. This is my problem. I go to my main folder where all other folders and subfolder with photos within them are placed. I want to look at my "Ratings" 5 starts, 4 stars and so forth. In other words I am looking for (searching for), in this case, all those photos I have labeled with 5 stars. But no such tab/filter exists in my main folder. Why? How do I perform such a task(look for all 5-star photos I have--and also zero stars, those yet to be labelled)?
    OS: WIndows 7 Home Premium 64bit
    Thank you

    The filter panel is a shortcut for the content panel and it only effects the content of that window. So if you have a folder it will only see this as a folder and not with its content. (a Stack behaves about the same, being different in only counting the first file in the filter panel criteria but not what is in the stack itself)
    You have a view work arounds, first is use menu view / show items from subfolders (this can take some time especially if you have not used caching before on this content) and this builds visible thumbs for all content and that can be used for filtering.
    Or use the find command (Edit / find) and inhere specify the source and fill in the criteria include subfolders and this will give you the correct result.
    When you create a smart collection the find command also pops up given you the same opportunity to get the results in a collection, but since a collection is only a bunch of aliases referring to the originals you might be a bit careful with editing and deleting.

Maybe you are looking for