home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / commlet / draw / goline.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.3 KB  |  78 lines

  1.  
  2. package como.commlet.draw;
  3.  
  4. import como.io.*;
  5. import como.util.*;
  6. import java.awt.*;
  7. import java.io.*;
  8. import java.util.*; import java.lang.*;
  9.  
  10. /******
  11. * GOPolygon
  12. */
  13. public class GOLine extends GraphicsObject
  14. {
  15.     int x2,y2;
  16.  
  17.     public GOLine()
  18.     {
  19.         super();
  20.         filled = false;
  21.     }        
  22.     public GraphicsObject getNew ()  {
  23.         GOLine go = new GOLine();
  24.         go.color = color;
  25.         go.name = name;
  26.         go.x = go.x2 = x;
  27.         go.y = go.y2 = y;
  28.         return go;
  29.     }
  30.  
  31.     public void draw(Graphics g,Color c)
  32.     {
  33.         lastgraphics = g;
  34.         g.setColor(c);
  35.         if ((x2 != x) || (y2 != y)) g.drawLine(x,y,x2,y2);
  36.     }        
  37.     public boolean handleEvent(Event evt)
  38.     {
  39.         if (evt.id == Event.MOUSE_UP)
  40.         {
  41.             evt.id = DrawCanvas.EVENT_ACCEPT;
  42.             return true;
  43.         }
  44.         else if (evt.id == Event.MOUSE_DOWN)
  45.         {
  46.             x = x2 = evt.x;
  47.             y = y2 = evt.y;
  48.             return true;
  49.         }
  50.         else if (evt.id == Event.MOUSE_DRAG)
  51.         {
  52.             if (evt.metaDown()) {
  53.                 if (Math.abs(evt.x-x) > Math.abs(evt.y-y))
  54.                     evt.y = y;
  55.                 else evt.x = x;
  56.             }
  57.             x2 = evt.x;
  58.             y2 = evt.y;
  59.             if (evt.target instanceof DrawCanvas) {
  60.                 ((DrawCanvas)evt.target).repaint();
  61.             }
  62.             return true;
  63.         }
  64.         return false;
  65.     }
  66. public void save(ObjectOutputStream s) throws IOException {
  67.     super.save(s);
  68.     s.writeInt(x2);
  69.     s.writeInt(y2);
  70.     }
  71. public void load(ObjectInputStream s) throws IOException {
  72.     super.load(s);
  73.     x2 = s.readInt();
  74.     y2 = s.readInt();
  75.     }
  76. }
  77.  
  78.