BidiEx.java

import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class BidiEx extends Frame {
  static String text = "<< Langue arabe >> se traduit" +
               "<< \u064a\u0628\u0631\u0639 >> en arabe";
  public BidiEx() {
    super("Exemple Bidi");
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) { System.exit(0); }
      });
    setBackground(Color.white);
    setFont(new Font("Lucida Sans", Font.PLAIN, 12));
    setSize(500, 150);
  }
  public void paint(Graphics g) {
    int height = 20;
    int y = 40;
    int x = 15;
    g.drawString(text, x, y);
    y += height * 2;
    g.drawString("morceau", x, y);
    g.drawString("niveau", x + 75, y);
    g.drawString("début", x + 150, y);
    g.drawString("fin", x + 200, y);
    g.drawString("texte", x + 250, y);
    y += height;
    Bidi bidi = new Bidi(text, Bidi.DIRECTION_LEFT_TO_RIGHT);
    byte[] levels = new byte[bidi.getRunCount()];
    for (int i=0; i<levels.length; ++i, y+=height) {
      int start = bidi.getRunStart(i);
      int limit = bidi.getRunLimit(i);
      g.drawString(Integer.toString(i), x, y);
      g.drawString(Integer.toString(bidi.getRunLevel(i)), x + 75, y);
      g.drawString(Integer.toString(start), x + 150, y);
      g.drawString(Integer.toString(limit), x + 200, y);
      g.drawString(text.substring(start, limit), x + 250, y);
    }
  }
  public static void main(String[] args) {
    new BidiEx().setVisible(true);
  }
}