Download code and jar files from src.zip.
This version of growbox allows the user to construct a
growbox
, then move and resize that growbox.
The cursors change to indicate the operation allowed
The default cursor indicates that another growbox may be initiated by pressing the mouse outside of the original growbox.
Test 1 (test1
) uses
XOR operations exclusively and does not call repaint
. The code in
question is shown below.
public void mouseDragged(MouseEvent event) { Graphics g = getGraphics(); int bx = base.x; int by = base.y; if (r==null) r = new growbox(); else r.draw(g); . . . r.draw(g); }
If the user resizes the window and moves the growbox, a “ghost” remains at the orginal position, as shown below
Test 2 (test2
) uses the
XOR operation to draw the growbox, but calls repaint
to refresh the screen. The code in
question is shown below.
public void mouseDragged(MouseEvent event) { int bx = base.x; int by = base.y; if (r==null) r = new growbox(); . . . repaint(); }
This version of the code does not produce artefacts.
Maintained by John Loomis, updated Mon Mar 16 16:30:27 2020