[2915] in java-interest

home help back first fref pref prev next nref lref last post

Pb with graphics.setPaintMode()

daemon@ATHENA.MIT.EDU (Francois Boussard)
Fri Oct 20 13:57:21 1995

Date: Fri, 20 Oct 1995 16:40:44 GMT
From: Francois Boussard <francois@coplanet.fr>
To: java-interest@java.sun.com
Cc: francois@coplanet.fr

----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 11

	Hy all,

	I found another bug : after a usage of XOR mode, you can't normaly
turn it off for using a desired color in paint mode  !.
	I send here source, html file, tried it on Netscape 2.0 Solaris 2.4.
	
	The problem is line 106 - 109

	I think it could be easily  fixed.

	By !
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: line.java
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 161

import java.applet.Applet;
import java.awt.Image;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Color;
import java.io.StreamTokenizer;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.net.URL;
import java.util.Hashtable;
import java.awt.image.IndexColorModel;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;


public class line 
extends java.applet.Applet 
implements Runnable 
{
  boolean alive=false;
  boolean painted=false;
  boolean topaint=false;
  boolean firstpaint=false;

  int l,h;
  int x0,y0,x1,y1,py,px,nx,ny;
  Color col;

  Image backBuffer;
  Graphics backGC;

  public synchronized void init() {
    l=size().width;
    h=size().height;
  }

  public void run() {
    try {
//      Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
      backBuffer = createImage(l,h);
      backGC = backBuffer.getGraphics();
      backGC.setColor(Color.white);
      backGC.fillRect(0,0,l,h);

      col=Color.red;
      alive = true;

    } catch(Exception e) {
      e.printStackTrace();
      alive = false;
    }
    repaint();
  }

  public void start() {
    if (alive == false ) new Thread(this).start();
  }

  public void stop() {    }

  public boolean mouseDown(Event e, int x, int y) {
    x0 = x;
    y0 = y;
    nx = x0;
    ny = y0;
    px = -1;
    py = -1;
    topaint=false;

    repaint();

    return true;
  }

  public boolean mouseUp(Event e, int x, int y) {
    x1 = x;
    y1 = y;
    topaint=true;
    repaint();
    return true;
  }

  public boolean mouseDrag(Event e, int x, int y) {
    nx=x;
    ny=y;
    painted = false;
    topaint=false;

    repaint();
    return true;
  }

  public void update(Graphics g) {
    l=size().width;
    h=size().height;
    if (backBuffer == null) g.clearRect(0, 0, l, h);
    paint(g);
  }

  public void paint(Graphics g) {
    if (alive) {
      if(topaint) {
	backGC.drawLine(x0,y0,px,py);

//----------------     PROBLEMS HERE
	backGC.setPaintMode();        /* Should turn Off the XOR Mode ! -> replace mode */
	backGC.setColor(Color.red);   /* Should Impose Red for nexts drawings ... */
	backGC.drawLine(x0,y0,x1,y1); /* Should draw a red line ?-> Losed : draw a black line ! */

//---------------  But, if you add those lines : you will have the rights colors !
/*
	backGC.setColor(Color.blue);
	backGC.drawLine(x0+2,y0+2,x1-2,y1-2);
*/



	g.drawImage(backBuffer, 0, 0, this);

	setPainted();
	topaint=false;
      }
      else {
	if((nx != px) || (ny != py)) {
	  backGC.setXORMode(Color.black);

	  if((px >= 0) && (py >= 0)) {
	    backGC.drawLine(x0,y0,px,py);
	  }

	  backGC.drawLine(x0,y0,nx,ny);

	  px = nx;
	  py = ny;
	  g.drawImage(backBuffer, 0, 0, this);
	  setPainted();
	}
      }
      if(! firstpaint){
	firstpaint=true;
	g.drawImage(backBuffer, 0, 0, this);
	setPainted();
      }
    }
  }

  private synchronized void setPainted() {
    painted = true;
    notifyAll();
  }

  private synchronized void waitPainted() {
    try {
      while (!painted) wait();
    }
    catch(Exception e) {
    }
    painted = false;
  }
}

----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: index.html
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 17

<html>
<head>
<title>
My Java devs
</title>
</head>

<body>


<applet code="line.class" width=500 height=500>
<param name=nb value=50>
</applet>


</body>
</html>
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post