How to Draw Line in Applet java code example
public static void drawLine(Graphics g, int i, int j, int k, int l, int i1)
{
if(i1 == 1)
{
g.drawLine(i, j, k, l);
return;
}
int j1 = k;
int k1 = l;
int l1 = i;
int i2 = j;
if(i == k)
{
j1 = (k + i1) - 1;
l1 = (i + i1) - 1;
} else
if(j == l)
{
k1 = (l + i1) - 1;
i2 = (j + i1) - 1;
} else
{
double d = (double)(l - j) / (double)(k - i);
double d1 = Math.sqrt(1.0D / (1.0D + d * d));
int j2 = (int)(d * d1 + (d <= 0.0D ? -0.5D : 0.5D));
int k2 = (int)(d1 + 0.5D);
j1 = k + j2;
k1 = l + k2;
l1 = i + j2;
i2 = j + k2;
}
g.drawLine(i, j, k, l);
g.drawLine(j1, k1, l1, i2);
g.fillPolygon(new int[] {
i, k, j1, l1
}, new int[] {
j, l, k1, i2
}, 4);
}
{
if(i1 == 1)
{
g.drawLine(i, j, k, l);
return;
}
int j1 = k;
int k1 = l;
int l1 = i;
int i2 = j;
if(i == k)
{
j1 = (k + i1) - 1;
l1 = (i + i1) - 1;
} else
if(j == l)
{
k1 = (l + i1) - 1;
i2 = (j + i1) - 1;
} else
{
double d = (double)(l - j) / (double)(k - i);
double d1 = Math.sqrt(1.0D / (1.0D + d * d));
int j2 = (int)(d * d1 + (d <= 0.0D ? -0.5D : 0.5D));
int k2 = (int)(d1 + 0.5D);
j1 = k + j2;
k1 = l + k2;
l1 = i + j2;
i2 = j + k2;
}
g.drawLine(i, j, k, l);
g.drawLine(j1, k1, l1, i2);
g.fillPolygon(new int[] {
i, k, j1, l1
}, new int[] {
j, l, k1, i2
}, 4);
}
Comments
Post a Comment