File: DrawArea.java

package info (click to toggle)
waba 1.5-3
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 1,996 kB
  • ctags: 3,231
  • sloc: ansic: 17,303; java: 4,436; sh: 2,345; makefile: 417
file content (46 lines) | stat: -rw-r--r-- 874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import waba.ui.*;
import waba.fx.*;

/**
 * A control that allows a user to draw using the pen or mouse.
 */

public class DrawArea extends Control
{
Graphics drawg;
int lastX, lastY;

public void onEvent(Event event)
	{
	if (drawg == null)
		{
		drawg = createGraphics();
		drawg.setClip(0, 0, this.width, this.height);
		}
	if (event.type == PenEvent.PEN_DOWN)
		{
		PenEvent penEvent = (PenEvent)event;
		lastX = penEvent.x;
		lastY = penEvent.y;
		}
	else if (event.type == PenEvent.PEN_DRAG)
		{
		PenEvent penEvent = (PenEvent)event;
		drawg.drawLine(lastX, lastY, penEvent.x, penEvent.y);
		lastX = penEvent.x;
		lastY = penEvent.y;
		}
	}

public void clear()
	{
	repaint();
	}

public void onPaint(Graphics g)
	{
	// erase draw area in white
	g.setColor(255, 255, 255);
	g.fillRect(0, 0, this.width, this.height);
	}
}