001: /*
002: * @(#)PlaneClient.java 1.4 03/01/16
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package IXCDemo.ixcXlets.clientXlet;
029:
030: import javax.microedition.xlet.Xlet;
031: import javax.microedition.xlet.XletContext;
032: import javax.microedition.xlet.ixc.IxcRegistry;
033: import java.rmi.NotBoundException;
034: import java.rmi.RemoteException;
035: import IXCDemo.shared.*;
036:
037: public class PlaneClient implements Xlet, PlaneListener {
038: private XletContext context;
039: private boolean started = false;
040: private Plane plane;
041:
042: public PlaneClient() {
043: System.out.println("client: constructed");
044: }
045:
046: public void initXlet(XletContext context) {
047: this .context = context;
048: }
049:
050: public void startXlet() {
051: System.out.println("PlaneClient starting...");
052: synchronized (this ) {
053: if (started) {
054: return;
055: }
056: started = true;
057: }
058: try {
059: System.out
060: .println("PlaneClient looking for import registry.");
061: IxcRegistry r = IxcRegistry.getRegistry(context);
062: System.out
063: .println("PlaneClient waiting for the server for 2 second");
064: Thread.sleep(2000);
065: System.out.println("PlaneClient looking for plane.");
066: plane = (Plane) r.lookup("");
067: System.out.println("PlaneClient adding self as listener.");
068: plane.addListener(this );
069: Plane other = (Plane) r.lookup("other");
070: System.out.println("Other plane: " + other);
071: System.out.println("Other equals primary? "
072: + other.equals(plane));
073: System.out.println("PlaneClient setting speed and heading");
074: plane.accelerate((float) 2.7);
075: plane.turn(Math.PI / 3.0);
076: System.out.println("Other equals primary? "
077: + other.equals(plane));
078: } catch (InterruptedException e) {
079: System.out.println("PlaneClient interruped");
080: context.resumeRequest();
081: } catch (NotBoundException ex) {
082: System.out.println("Server object not found");
083: ex.printStackTrace();
084: context.notifyDestroyed();
085: return;
086: } catch (RemoteException ex) {
087: System.out
088: .println("Client sees unexpected remote exception");
089: ex.printStackTrace();
090: context.notifyDestroyed();
091: return;
092: }
093: }
094:
095: public void pauseXlet() {
096: }
097:
098: public void destroyXlet(boolean unconditional) {
099: try {
100: plane.removeListener(this );
101: } catch (RemoteException ex) {
102: ex.printStackTrace();
103: }
104: }
105:
106: /* ============= Method from PlaneListener ================== */
107:
108: public void positionChanged(Position newPos) {
109: System.out.println("Client sees new position: " + newPos);
110: }
111: }
|