data.java

来自「《JAVA与模式》附书中源代码」· Java 代码 · 共 47 行

JAVA
47
字号
package com.javapatterns.observer.mvc;

/*
* This example is from javareference.com
* for more information visit,
* http://www.javareference.com
*/

//import statements
import java.util.*;

/**
* Data.java
* This class demonstrates the use of Observer Pattern
* This class represents the Data Object and extends the Observable
*
* @author Rahul Sapkal(rahul@javareference.com)
*/
public class Data extends Observable
{
    private int m_value;
        
    //Constructor
    public Data(int value)
    {
        m_value = value;
    }
    
    //set Data
    public void setData(int value)
    {
        m_value = value;
        
        //Make sure to set the hasChanged flas to true
        //otherwise the notifyObservers() call will not
        //notify the Observers
        setChanged();
    }

    //get Data
    public int getData()
    {
        return m_value;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?