WhiteBoard Using RMI
WSU CEG 7370 WhiteBoard Using Java RMI
LinesFrameImpl.java
Go to the documentation of this file.
1 // file LinesFrameImpl.java by pmateti@wright.edu
2 
3 package WhiteBoard;
4 
5 import java.io.*;
6 import java.util.*;
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.rmi.*;
10 
11 
12 public class LinesFrameImpl
13  extends java.rmi.server.UnicastRemoteObject
14  implements LinesFrame
15 {
16  private int x0 = 0, y0 = 0, x1, y1;
17  private static final int WIDTH = 300, HEIGHT = 300;
18  private Frame frame;
20  private String myURL, myCLientURL;
21 
22  private void deleteAndExit() {
23  try {
24  myWbClient.pleaseDie();
25  Naming.unbind(myURL);
26  } catch (Exception e) {e.printStackTrace();}
27  System.exit(0);
28  }
29 
30  WindowListener destroyWindow = new WindowAdapter() {
31  public void windowClosing(WindowEvent w) {
32  deleteAndExit();
33  }
34  };
35 
36  WindowListener raisedWindow = new WindowAdapter() {
37  public void windowActivated(WindowEvent w) {
38  try { myWbClient.sendAllLines(); }
39  catch (Exception e) {e.printStackTrace();}
40  }
41  };
42 
43  MouseListener getCoords = new MouseAdapter() {
44  public void mouseClicked(MouseEvent m) {
45  if (m.getModifiers() == InputEvent.BUTTON3_MASK)
46  deleteAndExit();
47 
48  try {
49  // get the coords, and send a line to our client
50  LineCoords ln = new LineCoords();
51  ln.x2 = m.getX();
52  ln.y2 = m.getY();
53  ln.x1 = x0;
54  ln.y1 = y0;
55  x0 = ln.x2; // store current point
56  y0 = ln.y2;
57  myWbClient.sendLine(ln);
58  } catch (Exception e) {e.printStackTrace();}
59  }
60  };
61 
62  public LinesFrameImpl(String [] args) throws Exception {
63  // args = [myId, bnm, displayMcnm, clientMcnm, clientId]
64  super();
65 
66  myCLientURL = Invoke.makeURL('C', args[4]);
67 
68  frame = new Frame(args[1] + "@" + myCLientURL + "@" + args[3]);
69  frame.setSize(WIDTH, HEIGHT);
70  frame.setVisible(true);
71  frame.addWindowListener(destroyWindow);
72  frame.addWindowListener(raisedWindow);
73  frame.addMouseListener(getCoords);
74 
75  myURL = Invoke.makeURL('D', args[4]);
76  myWbClient = (WbClient) Invoke.lookup(myCLientURL);
77  myWbClient.recvDisplayObj(this);
78  Invoke.myPrint("LinesFrameImpl", myURL);
79  Invoke.myPrint("LinesFrameImpl", ""+myWbClient);
80  Invoke.myPrint("LinesFrameImpl", "Done");
81  }
82 
83  public void recvOneLine(LineCoords ln) {
84  Graphics g = frame.getGraphics();
85  g.setColor(ln.c);
86  g.drawLine(ln.x1, ln.y1, ln.x2, ln.y2);
87  }
88 
89  public static void main(String[] args) {
90  try { LinesFrameImpl f = new LinesFrameImpl(args); }
91  catch (Exception e) {e.printStackTrace();}
92  }
93 }
94 
95 // -eof-
static Remote lookup(String url)
Definition: Invoke.java:77
void recvOneLine(LineCoords ln)
static void main(String[] args)
Copyright © 2014 www.wright.edu/~pmateti;   thanks to doxygen