當前位置: 首頁>>代碼示例>>Java>>正文


Java Observer類代碼示例

本文整理匯總了Java中java.util.Observer的典型用法代碼示例。如果您正苦於以下問題:Java Observer類的具體用法?Java Observer怎麽用?Java Observer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Observer類屬於java.util包,在下文中一共展示了Observer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: DataItemHolder

import java.util.Observer; //導入依賴的package包/類
public DataItemHolder ( final BundleContext context, final Item item, final DataSourceListener listener )
{
    super ( context, item, null );
    this.listener = listener;

    this.observer = new Observer () {

        @Override
        public void update ( final Observable o, final Object arg )
        {
            DataItemHolder.this.update ( o, arg );
        }
    };

    init ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:17,代碼來源:DataItemHolder.java

示例2: start

import java.util.Observer; //導入依賴的package包/類
public void start() {
    runBeforeActions();

    setStartTime(System.nanoTime());
    downloader.download();

    downloader.deleteObservers();
    downloader.addObserver(new Observer() {

        @Override
        public void update(Observable arg0, Object arg1) {
            if (downloader.getStatus() == Downloader.COMPLETED) {
                runAfterActions();
            }
        }

    });
}
 
開發者ID:mob41,項目名稱:osumer,代碼行數:19,代碼來源:Queue.java

示例3: createErrorListener

import java.util.Observer; //導入依賴的package包/類
@Override
protected Observer createErrorListener() {
    return new Observer() {
        @Override
        public void update(Observable observable, Object arg) {
            if (arg != null) {
                FormatError error = (FormatError) arg;
                if (error.getNumbers()
                    .size() > 1) {
                    int line = error.getNumbers()
                        .get(0);
                    int column = error.getNumbers()
                        .get(1);
                    select(line, column);
                }
            }
        }
    };
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:20,代碼來源:TextTab.java

示例4: createErrorListener

import java.util.Observer; //導入依賴的package包/類
/** Creates the listener of the error panel. */
private Observer createErrorListener() {
    return new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            if (arg != null) {
                AspectJCell errorCell = getJGraph().getModel()
                    .getErrorMap()
                    .get(arg);
                if (errorCell != null) {
                    getJGraph().setSelectionCell(errorCell);
                }
            }
        }
    };
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:17,代碼來源:StateDisplay.java

示例5: installListeners

import java.util.Observer; //導入依賴的package包/類
void installListeners() {
    getJGraph().addPropertyChangeListener(org.jgraph.JGraph.GRAPH_MODEL_PROPERTY,
        new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateModel();
            }
        });
    getJGraph().addGraphSelectionListener(new GraphSelectionListener() {
        @Override
        public void valueChanged(GraphSelectionEvent e) {
            clearSelection();
        }
    });
    getFilter().addObserver(new Observer() {
        @Override
        @SuppressWarnings("unchecked")
        public void update(Observable o, Object arg) {
            LabelTree.this.repaint();
            getJGraph().refreshCells((Set<JCell<G>>) arg);
        }
    });
    addMouseListener(new MyMouseListener());
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:25,代碼來源:LabelTree.java

示例6: initialize

import java.util.Observer; //導入依賴的package包/類
@Override
public void initialize() {
    super.initialize();

    // We run this code in the "initialize" method and not in the constructor, 
    // because at the time the constructor is run, the "actor" field of the 
    // test action is not yet populated.
    if (!AppiumTestAction.initialized) {
        AppiumTestAction.initialized = true;

        this.getActor().addObserver(new Observer() {
            @Override
            public void update(Observable eventSource, Object eventData) {
                if (eventSource instanceof ITestActor) {
                    if (eventData == TestActorEvents.TEST_COMPLETED) {
                        if (!AppiumHelper.getConfig().getBoolean("appium.reuseDriver", false)) {
                            AppiumHelper.discardDriver();
                        }
                    }
                }
            }
        });
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:25,代碼來源:AppiumTestAction.java

示例7: testImportExcelSingletonSuccess

import java.util.Observer; //導入依賴的package包/類
@Test
public void testImportExcelSingletonSuccess() {

    ResetTestValue.reset();

    ImportHandler handler = new ImportHandler(
            new RowRecordHandlerImpl(),
            new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON);
    List<RowRecord> list = handler.importExcel(
            ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")),
            new Observer() {
                @Override
                public void update(Observable o, Object arg) {
                    Process process = (Process) arg;
                    System.out.println("進度:" + process.getProcess() + ",當前階段:" + process.getNode());
                }
            },
            SchoolMan.class);
    for (RowRecord rr : list) {
        System.out.println(rr.getResult().getMsg());
    }
}
 
開發者ID:Strangeen,項目名稱:excel-util4j,代碼行數:23,代碼來源:TestImportHandler.java

示例8: testImportExcelSingletonError

import java.util.Observer; //導入依賴的package包/類
@Test
public void testImportExcelSingletonError() {

    ResetTestValue.reset();

    ImportHandler handler = new ImportHandler(
            new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON);
    List<RowRecord> list = handler.importExcel(
            ExcelFactory.newExcel(new File("D:/test/schoolman_error.xlsx")),
            new Observer() {
                @Override
                public void update(Observable o, Object arg) {
                    Process process = (Process) arg;
                    System.out.println("進度:" + process.getProcess() + ",當前階段:" + process.getNode());
                }
            },
            SchoolMan.class);
    for (RowRecord rr : list) {
        System.out.println("行號:" + rr.getRowNo() + ", 錯誤信息:" + rr.getResult().getMsg());
    }
}
 
開發者ID:Strangeen,項目名稱:excel-util4j,代碼行數:22,代碼來源:TestImportHandler.java

示例9: testImportExcelMultipleSuccess

import java.util.Observer; //導入依賴的package包/類
@Test
public void testImportExcelMultipleSuccess() {

    ResetTestValue.reset();

    ImportHandler handler = new ImportHandler(
            new RowRecordPersistencorHibernateImpl(factory), TransactionMode.MULTIPLE);
    List<RowRecord> list = handler.importExcel(
            ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")),
            new Observer() {
                @Override
                public void update(Observable o, Object arg) {
                    Process process = (Process) arg;
                    System.out.println("進度:" + process.getProcess() + ",當前階段:" + process.getNode());
                }
            },
            SchoolMan.class);
    for (RowRecord rr : list) {
        System.out.println(rr.getResult().getMsg());
    }
}
 
開發者ID:Strangeen,項目名稱:excel-util4j,代碼行數:22,代碼來源:TestImportHandler.java

示例10: main

import java.util.Observer; //導入依賴的package包/類
public static void main(String[] args) {
    Observer observer1 = new WeatherObserver();
    Observer observer2 = new WeatherObserver();
    Observer observer3 = new WeatherObserver();
    WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai")
            .temperature(22f)
            .humidity(0.8f)
            .forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f))
            .build();
    weatherSubject.addObserver(observer1);
    weatherSubject.addObserver(observer2);
    weatherSubject.addObserver(observer3);
    weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai")
            .temperature(28f)
            .humidity(9.8f)
            .forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f)));
}
 
開發者ID:goldonship,項目名稱:java-design-pattern,代碼行數:18,代碼來源:Application.java

示例11: testWeaterObserver

import java.util.Observer; //導入依賴的package包/類
@Test
public void testWeaterObserver() throws Exception {
    Observer observer1 = mock(WeatherObserver.class);
    Observer observer2 = mock(WeatherObserver.class);
    WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai")
            .temperature(22f)
            .humidity(0.8f)
            .forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f))
            .build();
    weatherSubject.addObserver(observer1);
    weatherSubject.addObserver(observer2);
    weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai")
            .temperature(28f)
            .humidity(9.8f)
            .forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f)));
    verify(observer1).update(weatherSubject, null);
    verify(observer2).update(weatherSubject, null);
}
 
開發者ID:goldonship,項目名稱:java-design-pattern,代碼行數:19,代碼來源:WeatherObserverTest.java

示例12: startGps

import java.util.Observer; //導入依賴的package包/類
private void startGps() {
    locationObserver = new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            Log.i(TAG, "update: Stopping Location");
            LocationProxy.getInstance().stopRequest(getApplicationContext());
        }
    };
    Log.i(TAG, "onCreate: AddObserver");
    LocationProxy.getInstance().addObserver(locationObserver);

    //Initializing location
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_GPS);
    else
        LocationProxy.getInstance().startRequest(this);
}
 
開發者ID:Baleine82,項目名稱:TrainPonctuality,代碼行數:18,代碼來源:MainActivity.java

示例13: main

import java.util.Observer; //導入依賴的package包/類
public static void main(String[] args) {

        System.err.println(
            "\nTest creating proxy class with the null class loader.\n");

        try {
            ClassLoader ld = null;
            Class p = Proxy.getProxyClass(ld, new Class[] { Runnable.class, Observer.class });
            System.err.println("proxy class: " + p);

            ClassLoader loader = p.getClassLoader();
            System.err.println("proxy class's class loader: " + loader);

            if (loader != null) {
                throw new RuntimeException(
                    "proxy class not defined in the null class loader");
            }

            System.err.println("\nTEST PASSED");

        } catch (Throwable e) {
            System.err.println("\nTEST FAILED:");
            e.printStackTrace();
            throw new RuntimeException("TEST FAILED: " + e.toString());
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:NullClassLoader.java

示例14: MacroViewer

import java.util.Observer; //導入依賴的package包/類
public MacroViewer() {
	setLayout(new BorderLayout());

	macroTable = new ExtendedJTable(dataModel, true, false, true);
	macroTable.setRowHeight(PropertyPanel.VALUE_CELL_EDITOR_HEIGHT);
	macroTable.setRowHighlighting(true);

	scrollPane = new ExtendedJScrollPane(macroTable);
	scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 5));
	add(scrollPane, BorderLayout.CENTER);

	updateQueue = new UpdateQueue(MACRO_VIEWER_DOCK_KEY);
	updateQueue.start();
	macroObserver = new Observer() {

		@Override
		public void update(Observable o, Object arg) {
			updateQueue.execute(new Runnable() {

				@Override
				public void run() {
					updateMacros();
					try {
						Thread.sleep(1000);  // Sleep 1sec to avoid update flooding
					} catch (InterruptedException e) {
					}
				}
			});
		}
	};
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:32,代碼來源:MacroViewer.java

示例15: attach

import java.util.Observer; //導入依賴的package包/類
private void attach ( final ConnectionService connectionService )
{
    detach ();

    this.item = new DataItem ( this.itemDescriptor.getItemId () );
    this.item.addObserver ( new Observer () {

        @Override
        public void update ( final Observable o, final Object arg )
        {
            ItemRegistration.this.handleUpdate ( (DataItemValue)arg );
        }
    } );
    this.item.register ( connectionService.getItemManager () );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:16,代碼來源:ItemRegistration.java


注:本文中的java.util.Observer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。