Do Java applets in your browser display Unicode?

From: Misha Wolf (MISHA.WOLF@reuters.com)
Date: Mon May 20 1996 - 16:40:27 EDT


To answer the question, try the Java applet in this message. The
applet was written by Nic Fulton, a colleague here at Reuters. Nic's
mail below is addressed to Martin Duerst, who asked for more info
following my earlier mail on the topic.

************

Martin,

Misha asked me to reply to your message about what we had
done to achieve Unicode with Java. I am working on a few
Java related projects (not Unicode directly) and I got a
Sparc 5 workstation to do some development work on. This
arrived about 10 days ago, and I installed Solaris 2.5
straight from the CD and that was about it. I did add an
extra package called:

X Windows I18N Common Package

but as this is smaller that one MegaByte I can not
imagine this contains the fonts, I presume they are
in the default X Windows common and required fonts packages.

The browser that I am using is Netscape Atlas PreRelease 2.
The characters do not appear in Unicode in appletviewer.

I will include in this message an HTML file and the applet
source code that I used to test the system (after the
initial discovery using Charles applet). Please feel free
to put this applet up on this Internet if you would like.
If you make changes (it needs a few !), then please let
me know so I can change my local copy. Misha will be
sending it out to some mailing lists shortly. I am a true
Java Cowboy so don't expect too many comments or nicely
written code !!!

I hope this is all useful,

Regards,

Nic.

--- Unicode.html ---

<html>
<head>
<title>Unicode Java Test</title>
</head>
<body>
<h1>Unicode Java Test</h1>
<applet code="Unicode.class" width=475 height=475>
</applet>
</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