Implementing evetns in my own classes

I am currently developing a class that I want to enable with events so that consumers of my class can get feedback of class activity.
So consumers should be able to add listeners (containing callback methods) to instances of the class. Although my current class is GUI related (I am writing my own tablemodel) my issue is not limited to GUI development I think (therefore posted here and not in Swing forum).
So far I am a little familiar with Listener and Adapter classes but now the point:
Do I have to implement my own addBlaBlaListener and removeBlaBlaListener methods implementing my own methods to handle the list of current listeners (e.g. choosing the appropriate array, list, stack or whatever classes to store the references) or is there some ready-made-classes from the libraries that should/can be used?

tjacobs01 wrote:
Why do you need to create UI-style events?I am building my own Table model as the simple table model is too basic for my common needs. In that table model I need to provide events being fired when table cells change.
I highly recommend using the Observable/Observer pattern where possible. Otherwise, see an example for custom events in my InfoFetcher.FetcherListener interface
http://forums.sun.com/thread.jspa?threadID=759854&tstart=62264
I heard/read about the Observer and Observerable but when I searched for event handling I always found the methods I am currently trying. That's the only reason why I use that here - because this is what I found how others recommend to do it. If there is a better option - I am open and flexible - yet (in a year when everything was implemented probably not ;-) ).

Similar Messages

  • (updated)UIScrollBar and my own class. Can they works together?

    Hi Eone,
    i'm implementing a uiscrollbar in a class of mine that extends textfield. Unluckly it gives to me  a lot of 1120 error, undefined property, in each row i use a property of this component (except the constructor).
    I read somewhere that As2 not allow to use uisbar in other type of class that extends movieclip or textfiled or you know what...
    It's the same in As3?
    EDIT:
    I found a solution. Some method an properties of UISB can be used in the cvlass (like, contructor, update, target). Some otherelse not. So the other can be used only when i do an instance of my own class, like properties of the instance. Ex:
    textfield.UISB.x = 100;
    textfield: instance of my class
    UISB: scrollbar declared within my class
    x= properties defined only instancing my class

    You need to read the basics about Swing events.
    For starters, you do not implement listeners in your Applet class. Instead, you add new listeners to specific components that you want to listen on. For example, if you need to perform certain actions when a JComboBox's selection changes, you would do something like:
    my_combo.addActionListener(  new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("selection changed to: " + my_combo.getSelectedItem());
    });And for buttons:
    my_button.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You clicked " + ((JButton) e.getSource()).getText() " button);
    }MoustListener and other listeners can be similarily added. See JDK Documentation or Tutorials

  • Interfaces for your own classes - do you bother?

    Hi All,
    before anyone gets upset, I did post a shorter version this to the Java Prog forum a couple of days ago. I'm reposting here because the thread was pushed down the list just as comments were getting interesting, and I was tossing up which forum was most appropriate anyway...
    OK, I'd like to pose a general question on the use of interfaces with your own classes. I am totally behind the concept of using appropriate interfaces for declaration of vars, parameters etc (i.e. use "List" rather than "Vector"), but what about your own classes?
    If I have a class in my application that doesn't fit into any kind of framework or class hierarchy, subclass of object basically, should I write an interface with all the same method sigs and use that rather than the class for my vars, params etc? This would make things more flexible in future, enabling you to swap classes in and out of your app more easily.
    Taking it a step further, how's this for a design methodology: For every class you write (once again classes that don't fit into your own or somebody else�s hierarchy or framework) do the following
    1. Create an interface (MyInterface) that maps 1 to 1 to that class (MyClass), with all the same method sigs.
    2. Make the constructor private and manage all the creation of instances of MyClass through a factory that returns objects of type MyInterface.
    If you do this there will be no mention of any of your concrete classes anywhere in your app except the factories, making it easier to refactor etc. Do this for all your classes.
    A little sketchy but I hope you get idea. Is this complete overkill? Is there a down side to this? Does anyone do anything like this?
    Cheers
    Matt

    Although the pattern you describes adds flexibility, it also adds complexety.
    Imagine somebody is looking at your code and from what he sees he deducts that the next thing to look at is the concrete class which is used at a given place.
    If you used an interface, he must find out which implementing class is actually used at this place. It's not a big thing, but if every single class has its seperate interface and factory I would consider it overkill ... after all you have to write all the boring code for this.
    In the case of doubt I'd agree it's better to throw in an interface and a factory instead of refactoring thousand lines of codes afterwards. But if nothing hints toward a second implementation of the interface, or another reason for using an interface don't bother to write one.
    As a general rule I use something like: Don't use a general rule. ;-)
    Spieler

  • Problem with creating my own class...

    Hi all,
    Purpose with this program:
    I want to create my own class StringThing which take a string parameter and transform the content toUpperCase().
    I have created a simple class StringThing which look like this:
    class StringThing {
    public String upperize (String u) {
    u.toUpperCase();
    return u;
    }And my class where I use the StringThing looks like this:
    import java.io.*;
    class UseStringThing{
    public static void main (String arg[]) throws Exception {
    BufferedReader keyboard = new BufferedReader(
    new InputStreamReader(System.in));
    String s,p;
    System.out.prinln("write a sentence!");
    s=keyboard.readLine();
    StringThing thing = new StringThing();
    p=thing.upperize(s);
    System.out.println(p);
    }Am I not supposed to transform my string parameter in my class by using for instance toUpperCase()? Or is there some fundamental rule or piece of code which I forgot?
    Thanks in advance,
    /Beginner-T-who-ripps-his-hear-over-this-small-problem

    Strings cannot be modified. What this line does:
    u.toUpperCase();
    is to create a new String object. toUpperCase() returns the newly created string and you are ignoring the returned value. What you want to do is:
    return u.toUpperCase();
    or
    u = u.toUpperCase();

  • How can I create a new own class in WebDynpro?

    I test the Web Dynpro for a while and found all the java classes were generated automatically. I've tried to create an own class. But after I rebuild the project, all of my own classes were cleared.

    Hi
    You can create your own class as mentioned in above replies or one more way,
    1. first you create your java project seperately,  there you can write all your business needs and then, make a jar or that then, you can include that project into your WDproject by
    rightclick on WDproject>properties>libraries>addexternaljars>ok
    2. create seperate java project
    rightclick on WDproject>properties>Projects>selectYourjavaProject>ok
    Regards
    Abhijith YS

  • How to get context information in your own class

    Hi,
    I'm new to Java and I'm trying to create my own class which stores some constants like for example mailServerHost. The class would look something like this:
    public class AppSettings {
    private static String mailServerHost="localhost";
    static{
    if(###online-server###)
    mailServerHost="another mail server";
    My problem is the if(###online-server###). I don't know how could I find informations about the underlying server.
    Is there any way to find out informations about the context(server)?
    Thanks,
    IMIA

    Do you still need ?n this case 2 different
    property-files (one for dev and one for
    online-servers).Yes, but they would have the same name. ;-)
    After all when you need to load one
    of them you'd still need in your AppSettings class on
    which server your application is running. So I'd
    still need that information.No, you use a fixed name, e.g. server.properties, for the config file.
    You might find class java.util.ResourceBundle interesting.

  • HELP: Import my own class in JSP ???

    Hi, all!
    I read many previous topics in this forum but no one works for me!
    Please someone help me!
    I'm using Tomcat 4.1.12 and my JSP scripts work just fine, but I need to import my own .class file. I just don't know where to put it so Tomcat can find it!?
    I have this environment variable:
    JAVA_HOME=.;c:\jdk1.3.1
    And in my code I'want to place something like this:
    <%@ page import="myClass" %>
    But I get a "can not resolve symbol" exception.
    Thanks for readind this, and please help if you can!
    Bye.
    adriano

    Within the Tomcat directory, under your application directory place the class file/s into the WEB-INF/classes directory. If your classes are part of a package place the entire directory structure of the package under the WEB-INF/classes directory.
    The import in the JSP is the same as for any Java class.
    Hope this solves your problem.

  • How to create an object of our own class by using Class.forName()??

    how to create an object of our own class by using Class.forName()??
    plzz anser my qustion soon..

    Class.forName does not create an object. It returns a reference to the Class object that describes the metadata for the class in question--what methods and fields it has, etc.
    To create an object--regardless of whether it's your class or some other class--you could call newInstance on the Class object returned from Class.forName, BUT only if that class has a no-arg constructor that you want to call.
    Class<MyClass> clazz = Class.forName("com.mycompany.MyClass");
    MyClass mine = clazz.newInstance();If you want to use a constructor that takes parameters, you'll have to use java.lang.reflect.Constructor.
    Google for java reflection tutorial for more details.
    BUT reflection is often abused, and often employe when not needed. Why is it that you think you need this?

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • No intelli sense on my own classes

    I don't get a drag-down intelli-sense menue when i
    type the name of one of my own classes and press ctrl+space.
    Anyone who has had the simular problem, and know the answer?
    The classes are all in the same package.

    Through the tools menue for the folder and "update parser database..."?
    In that case I have to do it for each folder/project?
    I'd like to have it done automaticly. On some other
    computers I have programmed on, the drop-down-menu
    appears without me updating the parser database.
    Has it something to do with the setup?

  • Can Access Outside Dll's Friend Functions On Own Class

    Can Access Outside Dll's Friend Functions On Own Class?
    For Example:
    System.Web.Util's SecUtility ?SecUtility is : internal static class SecUtility

    See the answer by nobugz to this
    thread.

  • I need  to implement clone method  in theAdvancedDataGrid class

    I need  to implement clone method  in theAdvancedDataGrid class, to copy the object in its completeness   Could anyone give me a helping hand.

    Hi Nikos,
    from youe question it's not clear what do you need to copy: data, parts of ADG (GUI) or something else?
    If it's not a GUI - only data - you can use mx.utils.ObjectUtil.copy(value:Object):Object

  • How to implement your own class.......I don't have a clue, please help!

    I'm new with Java and am so confused! I need help with the following exercise.
    Implement a class Employee. An employee has a name (a string) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods to return the name and salary. Write a program that tests your class. How do I do this?
    I can't figure out how to do this!!!!! Please show me an example!

    public class Employee {
      private String name;
      private double salary;
      public static void main(String[] args) {
        Employee employee = new Employee("Max Just", 64000);
        System.out.println(employee.getName() + "\nsalary: " + employee.getSalary());
      public Employee() {
        name = null;
        salary = null;
      public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
      public String getName() {
        return name;
      public double getSalary {
        return salary;

  • Loading a library in my own class...

    Hello,
    I'm having some problems with loading my own library into a different class then the main, but I'm keep getting this error message:
    run:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: cembedjava.CFunctions.nativePrint()V
            at cembedjava.CFunctions.nativePrint(Native Method)
            at cembedjava.Main.main(Main.java:17)
    Java Result: 1The project is based around the tutorial for including some C code in a Java application. I'm working with an Ubuntu 8.10 distro, Netbeans IDE 6.1 and JDK 6 update 11. I'm new to Java programming, but I have experience with C, Delphi and Basic in different flavours.
    The C code is working as it supposed to be (at least, I think, I had it running under the main class). The code implements a timer in C with an interval period of 1,5 seconds, which returns a message every time to the screen (or app). What's going wrong in the following code?
    package cembedjava;
    public class CFunctions
         public native void nativePrint(); 
         static {
           System.load("/home/richard/NetBeansProjects/HelloWorldNative/dist/libHelloWorldNative.so");
          // System.loadLibrary("libHelloWorldNative");
    package cembedjava;
    import java.lang.Thread;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class Main {
        public static void main(String[] args) {
            // TODO code application logic here
           CFunctions obj = new CFunctions();
           obj.nativePrint();
    }Or do I need a new thread to keep my timer running?
    Thanks

    Thanks guys,
    I got it working... I had a problem with the declaration of the function in my .h and .c file. In the .h file everything was okay, but I had the wrong classname in the .c file. For some reason this still compiled but gave me the exception during runtime.
    Is there also a possibility not to have to put in the class name in the function declaration, right now the function are declared as this:
    JNIEXPORT void JNICALL Java_cembedjava_CFunctions_nativePrint
          (JNIEnv *env, jobject obj)
    With the CFunctions as class name en cembedjava as project name of the Java project. Is it possible to call my functions in a project and class that don't have the above stated names?

  • Check on  Implementation being used in a class

    Hi Al,
    We have a requirement of using one method of  using one implimentation of a class but we have two implementations available .Is ther any check where in we can specify the usage of one implementation and ignoring the other
    One way of doing it is to inactivate the implementation not needed but is there any other way of doing it.
    It's urgent any help is highly appreciated.
    Regards,
    Rajashree

    Using the below FM:
    SUSR_USER_AUTH_FOR_OBJ_GET
    EFG_USER_AUTH_FOR_OBJ_GET
    You can get all the autority check available for a user.
    Regards,
    Prakash.

Maybe you are looking for

  • Billing plan reference joined to a material number

    Hello to all We have to join material number with a billing plan reference before the creation of the sales order. The issue is that you can join a billing plan reference(with the distribution of the amount between the different dates in a percent) w

  • The feature: "Report part gallery" is not supported in this edition of Reporting Services.

    Struggling trying to get off the ground on same basic reporting functionality - I have a report that basically just dumps out the contents of a table for now.  When I attempt to publish the report, I get "The feature: "Report part gallery" is not sup

  • My macbook pro's desktop and screen saver is not responding

    My mac book pro when started pops up a window which shows desktop and screen saver and it becomes nonresponsive, eventhough it is force quit it pops again and keeps searching for something .

  • Create Journals for Closed Period

    HI, In July, the user forgot to run journal entries in FA subledger, so the depreciation expenses didn't get posted to GL. So there were variances between FA and GL. How to capture the July Depreciation journal entries, since the period is already cl

  • CS4: upgrade to CS6 or the Cloud?

    I currently have CS4, and have bought a new Mac which wants me to downgrade Java to 6. Should I upgrade from CS4 to CS6 instead or, if possible, upgrade to the cloud. I consider myself a novice+ CS user.