Java Source Code
Transpose Applet
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.lang.*;
public class Transpose extends Applet
{
Graphics sG;
Graphics bG;
Image bI;
Image matrices;
Color blue = new Color(0, 0, 255);
int x = 0;
int y = 0;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
matrices = getImage(getCodeBase(), "transpose.gif");
bG.drawImage(matrices, 0, 0, this);
drawscreen();
}
public void paint(Graphics g)
{
drawscreen();
g.drawImage(bI, 0, 0, this);
sG = getGraphics();
}
public void drawscreen()
{
bG.drawImage(matrices, 0, 0, this);
check(x, y, 58, 6, 58, 6);
check(x, y, 58, 28, 97, 6);
check(x, y, 58, 78, 172, 6);
check(x, y, 97, 6, 58, 28);
check(x, y, 97, 28, 97, 28);
check(x, y, 97, 78, 172, 28);
check(x, y, 172, 6, 58, 78);
check(x, y, 172, 28, 97, 78);
check(x, y, 172, 78, 172, 78);
}
public void box(int ix, int iy)
{
bG.setColor(blue);
bG.drawLine(ix, iy, ix + 30, iy);
bG.drawLine(ix, iy + 20, ix + 30, iy + 20);
bG.drawLine(ix, iy, ix, iy + 20);
bG.drawLine(ix + 30, iy, ix + 30, iy + 20);
}
public boolean mouseDown(Event evt, int mx, int my)
{
x = mx;
y = my;
drawscreen();
sG.drawImage(bI, 0, 0, this);
return true;
}
public void check(int x, int y, int tx, int ty, int px, int py)
{
if ((x >= tx) && (x < tx + 31) && (y >= ty) && (y < ty + 21))
{
box(tx, ty);
box(px + 228, py + 1);
}
if ((x >= px + 228) && (x <= px + 259) && (y >= py) && (y < py + 21))
{
box(tx, ty);
box(px + 228, py + 1);
}
}
}
Multiplication Applet
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.lang.*;
public class Multiply extends Applet
{
Graphics sG;
Graphics bG;
Image bI;
Image matrices;
Color blue = new Color(0, 0, 255);
int x = 0;
int y = 0;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
matrices = getImage(getCodeBase(), "multiply.gif");
bG.drawImage(matrices, 0, 0, this);
drawscreen();
}
public void paint(Graphics g)
{
drawscreen();
g.drawImage(bI, 0, 0, this);
sG = getGraphics();
}
public void drawscreen()
{
bG.drawImage(matrices, 0, 0, this);
check(x, y, 383, 3, 188);
check(x, y, 420, 3, 226);
check(x, y, 493, 3, 298);
check(x, y, 383, 25, 188);
check(x, y, 420, 25, 226);
check(x, y, 493, 25, 298);
check(x, y, 383, 75, 188);
check(x, y, 420, 75, 226);
check(x, y, 493, 75, 298);
}
public void check(int x, int y, int px, int py, int qx)
{
if((x >= px) && (x <= px + 30) && (y >= py) && (y <= py + 20))
{
box(px, py);
bG.setColor(blue);
bG.drawLine(13, py, 155, py);
bG.drawLine(13, py + 20, 155, py + 20);
bG.drawLine(13, py, 13, py + 20);
bG.drawLine(155, py, 155, py + 20);
bG.drawLine(qx, 1, qx, 95);
bG.drawLine(qx + 30, 1, qx + 30, 95);
bG.drawLine(qx, 1, qx + 30, 1);
bG.drawLine(qx, 95, qx + 30, 95);
}
}
public void box(int ix, int iy)
{
bG.setColor(blue);
bG.drawLine(ix, iy, ix + 30, iy);
bG.drawLine(ix, iy + 20, ix + 30, iy + 20);
bG.drawLine(ix, iy, ix, iy + 20);
bG.drawLine(ix + 30, iy, ix + 30, iy + 20);
}
public boolean mouseDown(Event evt, int mx, int my)
{
x = mx;
y = my;
drawscreen();
sG.drawImage(bI, 0, 0, this);
return true;
}
}
Copyright c 1997 by
Frank Wattenberg, Department of Mathematics, Montana State University,
Bozeman, MT 59717