Search code examples
javaeventsjava-me

How to replace javax.microedition.event.Event when porting from Java ME to SE?


When porting a large project with 5000 Java-files from Java ME to Java SE, I have tried to replace javax.microedition.event.Event with my own class (same for EventManager and EventListener):

public class Event extends java.util.EventObject {
    protected String mName;
    protected Object mValue;
    protected String mMessage;
    protected Object mInfo;

    public Event(Object source) {
        super(source);
    }

    public Event(String event, String value, String message, Object info) {
        super(null); // throws IllegalArgumentException

        mName = event;
        mValue = value;
        mMessage = message;
        mInfo = info;
    }

Unfortunately, the base class java.util.EventObject does not like the source being null.

I have searched around and couldn't find any suitable Java source code.

My question is:

How to write a replacement for the constructor public Event(String event, String value, String message, Object info) here? How to set the source, where to get it?


Solution

  • public class Event extends java.util.EventObject {
    
        public static final Object UNKNOWN_SOURCE = new Object();
    
        public Event(String event, String value, String message, Object info) {
            super(UNKNOWN_SOURCE);
    
            mName = event;
            mValue = value;
            mMessage = message;
            mInfo = info;
        }