Thursday, 27 February 2014

BASIC GRAPHICS IN JAVA WITH EXAMPLE

SETTING THE PAINT MODE

set drawing mode to XOR  example..........

PAINTING MODE:


There are two painting or drawing modes for the Graphics class:- paint mode which is the default mode and XOR mode. In paint mode, anything we draw replaces whatever is already on the screen i.e. it overwrites any preexisting contents. If you draw a green circle, you get a green circle, no matter what was underneath.The paint mode determines how objects are drawn in a window. It is possible to have new objects XORed on to the window by using setXORMode().

Syntax

void setXORMode(Color XORColor)


XORColor:-color that will be XORed to the window when an object is drawn.

The advantage of XORMode is that the new object is always guaranteed to be visible no matter what color the object is drawn over.

To return the overwrite mode,call setPaintMode().

Syntax

void setPaintMode()

EXAMPLE:

/*<applet code="XOR" width=200 height=100> </applet>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class XOR extends Applet
{
int x=100,y=50;
public void paint(Graphics g)
{
g.setXORMode(Color.green);
g.drawLine(chsx-50,chsy,chsx+10,chsy);
g.setPaintMode();
}
}

OUTPUT:







1 comment :

  1. Simplest understandable explaination of the Paint mode-really appreciating thanks for ur efforts

    ReplyDelete