Re: Do Java applets in your browser display Unicode?

From: Misha Wolf (MISHA.WOLF@reuters.com)
Date: Tue May 21 1996 - 12:52:51 EDT


I've been asked whether the Java applet mentioned in my earlier mail is
available on the Web. How about putting the appended (improved) HTML
page plus Java applet on the Unicode Web site, so people can test their
browsers?

misha.wolf@reuters.com

--- Unicode.html ---

<html>
<head>
<title>Unicode Java Test</title>
</head>
<body>
<h1>Unicode Java Test - by Nic Fulton of
<a href="http://www.reuters.com">Reuters</a> </h1>
<hr>
<b><h2>Question: Do Java applets in your browser display
Unicode?</h2></b>
<b><h2>Answer: Look at the applet below...</h2></b><br>
<center>
<applet code="Unicode.class" width=475 height=475>
</applet>
</center>
<p>
The slider at the base represents the first of the four hex digits
of a Unicode character. The right-hand slider represents the second
digit. The grid of 256 cells should show the 256 characters whose
Unicode code points start with those two hex digits.
<p>
For instance, Kanji characters start at
4E00. Place the bottom slider against "4", the right-hand slider
against "e" and you should see lots of Kanji characters.
<p>
If you do, the answer to the above question is <b>"Yes!"</b>
or <b>":-)"</b>.
<p> If you don't, the answer is <b>"No"</b>, or <b>":-("</b>.
<p>If you click on a character it <i>should</i> be magnified in the
box in the bottom right corner. However, this will depend on your
system having support for enlarged versions of the character.
<hr>
</body>
</html>

--- Unicode.java ---

import java.awt.*;
import java.applet.*;

// Unicode.java - a simple Unicode testing applet
// Nic Fulton - nic.fulton@reuters.com
// 20th May 1996

public class Unicode extends Applet
{
    public void init()
    {
        // Hardcode all of the layout (cowboy style)
        setLayout(null);
        theCharPanel = new CharPanel();
        add(theCharPanel);
        theCharPanel.reshape(400,400,75,75);
        theTextPanel = new TextPanel(theCharPanel);
        add(theTextPanel);
        theTextPanel.reshape(0,0,400,400);
        theBottomPanel = new BottomPanel(this);
        add(theBottomPanel);
        theBottomPanel.reshape(0,400,400,75);
        theRightPanel = new RightPanel(this);
        add(theRightPanel);
        theRightPanel.reshape(400,0,75,400);
    }

    public void setIOff(int i)
    {
        theTextPanel.setIOff(i);
    }

    public void setJOff(int j)
    {
        theTextPanel.setJOff(j);
    }

    TextPanel theTextPanel;
    BottomPanel theBottomPanel;
    RightPanel theRightPanel;
    CharPanel theCharPanel;
}

// The grid of characters extending a Canvas

class TextPanel extends Canvas
{
    public TextPanel(CharPanel theCharPanel)
    {
        this.theCharPanel = theCharPanel;
    }

    public void paint(Graphics g)
    {
        g.drawRect(0,0,400-1,400-1);
        for(int i=1;i<16;i++)
        {
            g.drawLine(0,i*25,400,i*25);
            g.drawLine(i*25,0,i*25,400);
        }
        for(int i=0;i<16;i++)
        {
            for(int j=0;j<16;j++)
            {
                char Chars[] = new char[1];
                int anInt = j + i*16 + jOff*256 + iOff*4096;
                Chars[0] = (char)anInt;
                g.drawChars(Chars,0,1,i*25 + 4, j*25 +21);
            }
        }
    }

    public boolean mouseDown(Event evt, int x, int y)
    {
        int i = x/25;
        int j = y/25;
        theCharPanel.setChar(j,i,jOff,iOff);
        return true;
    }

    public void setIOff(int i)
    {
        iOff = i;
        repaint();
    }

    public void setJOff(int j)
    {
        jOff = j;
        repaint();
    }

    int jOff = 0;
    int iOff = 0;
    CharPanel theCharPanel;
}

// The bottom slider, well sort of, control extending Canvas

class BottomPanel extends Canvas
{
    public BottomPanel(Unicode theApplet)
    {
        this.theApplet = theApplet;
    }

    public void paint(Graphics g)
    {
        g.fillRect(0,0,400,25);
        Color aColor = g.getColor();
        g.setColor(Color.white);
        for(int i=0;i<16;i++)
        {
            g.drawString(Integer.toString(i,16), i*25 + 7, 20);
        }
        g.setColor(aColor);

        g.drawRect(0,50,400-1,24);
        for(int i=1;i<16;i++)
        {
            g.drawLine(i*25,50, i*25,75);
        }
        g.fillRect(myI*25,50,25,25);
    }

    public boolean mouseDown(Event evt, int x, int y)
    {
        int i = x/25;
        myI = i;
        repaint();
        theApplet.setIOff(i);
        return true;
    }

    public boolean mouseDrag(Event evt, int x, int y)
    {
        int i = x/25;
        myI = i;
        repaint();
        theApplet.setIOff(i);
        return true;
    }

    Unicode theApplet;
    int myI = 0;
}

// The right slider, well sort of, control extending Canvas

class RightPanel extends Canvas
{
    public RightPanel(Unicode theApplet)
    {
        this.theApplet = theApplet;
    }

    public void paint(Graphics g)
    {
        g.fillRect(0,0,25,400);
        Color aColor = g.getColor();
        g.setColor(Color.white);

        for(int i=0;i<16;i++)
        {
            g.drawString(Integer.toString(i,16), 7, i*25+20);
        }
        g.setColor(aColor);

        g.drawRect(50,0,24,400-1);
        for(int i=1;i<16;i++)
        {
            g.drawLine(50,i*25,75,i*25);
        }
        g.fillRect(50,myJ*25,25,25);
    }

    public boolean mouseDown(Event evt, int x, int y)
    {
        int j = y/25;
        myJ = j;
        repaint();
        theApplet.setJOff(j);
        return true;
    }

    public boolean mouseDrag(Event evt, int x, int y)
    {
        int j = y/25;
        myJ = j;
        repaint();
        theApplet.setJOff(j);
        return true;
    }

    Unicode theApplet;
    int myJ = 0;
}

// An area for a bigger character - remember that not all fonts can
grow
// forever

class CharPanel extends Canvas
{
    public CharPanel()
    {
        theChar = (char)0x5858;
    }

    public void paint(Graphics g)
    {
        g.drawString(Integer.toString((int)theChar,16),23,20);
        g.drawRect(25,25,49,49);
        Font Font1 = g.getFont();
        Font Font2 = new Font(Font1.getFamily(), Font1.getStyle(),
Font1.getSize()*2);
        g.setFont(Font2);
        char aChar[] = new char[1];
        aChar[0] = theChar;
        g.drawChars(aChar, 0, 1, 32, 68);

    }

    public void setChar(int a, int b, int c, int d)
    {
        int i = a + b*16 + c*256 + d*4096;
        theChar = (char)i;
        repaint();
    }

    char theChar;
}

--- End of included Text ---



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:31 EDT