Posts

Showing posts from June 26, 2010

How to convert Integer Array to String in java code examples

public static String arrayToString(Integer[] a, String separator) {
    String result = "";
    if (a.length > 0) {
        result = a[0].toString();    // start with the first element
        for (int i=1; i
            result = result + separator + a[i];
        }
    }
    return result;
}

How to Draw Oval in Applet Java Code example

public static void drawOval(Graphics g, int i, int j, int k, int l, int i1)
    {
        if(i1 == 1)
        {
            g.drawOval(i, j, k, l);
            return;
        }
        i -= i1 / 2;
        j -= i1 / 2;
        k += i1;
        l += i1;
        for(int j1 = 0; j1 < i1; j1++)
        {
            g.drawOval(i, j, k, l);
            if(j1 + 1 < i1)
            {
                g.drawOval(i, j, k - 1, l - 1);
                g.drawOval(i + 1, j, k - 1, l - 1);
                g.drawOval(i, j + 1, k - 1, l - 1);
                g.drawOval(i + 1, j + 1, k - 1, l - 1);
                i++;
                j++;
                k -= 2;
                l -= 2;
            }
        }

    }

How to Draw a circle in Applet java Code example

public static void drawCircle(Graphics g, int i, int j, int k, int l)
    {
        k += l / 2;
        for(int i1 = 0; i1 < l; i1++)
        {
            drawCircle(g, i, j, k);
            if(i1 + 1 < l)
            {
                drawCircle(g, i + 1, j, k - 1);
                drawCircle(g, i - 1, j, k - 1);
                drawCircle(g, i, j + 1, k - 1);
                drawCircle(g, i, j - 1, k - 1);
                k--;
            }
        }

    }

How to Draw Rectangle in Applet java code?

// Draw Rectangle in Applet java code

public static void drawRect(Graphics g, int i, int j, int k, int l, int i1)
    {
        i -= i1 / 2;
        j -= i1 / 2;
        k += i1;
        l += i1;
        for(int j1 = 0; j1 < i1; j1++)
        {
            g.drawRect(i, j, k, l);
            i++;
            j++;
            k -= 2;
            l -= 2;
        }

    }

How to calculate no of files in a directory in java code examples

private static int calNoOfFiles(String directoryPath)
    {
        File fd = new File(directoryPath);
        if(!fd.isFile())
        {
            String list[] = fd.list();
            for(int i = 0; i < list.length; i++)
            {
                String tempDirPath = directoryPath + fileDelimiter + list[i];
                debug(tempDirPath);
                File ftd = new File(tempDirPath);
                if(ftd.isFile())
                    noOfFiles++;
                if(ftd.isDirectory())
                    calNoOfFiles(tempDirPath);
            }

        }
        return noOfFiles;
    }

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
        }, …

Recent Post

Recent Posts Widget