如何在从Java ME移植到SE时替换javax.microedition.event.Event?

时间:2016-04-18 11:11:20

标签: java events java-me

当将包含5000个Java文件的大型项目从Java ME移植到Java SE时,我尝试将javax.microedition.event.Event替换为我自己的类(EventManagerEventListener相同):

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;
    }

不幸的是,基类java.util.EventObject不喜欢sourcenull

我已经搜索过,无法找到任何合适的Java源代码。

我的问题是:

如何在此处为构造函数public Event(String event, String value, String message, Object info)编写替换代码?如何设置source,从哪里获取它?

1 个答案:

答案 0 :(得分:2)

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;
    }