Thread: iLiad xlets!
View Single Post
Old 05-15-2007, 04:47 PM   #1
scotty1024
Banned
scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.
 
Posts: 1,300
Karma: 1479
Join Date: Jul 2006
Location: Peoples Republic of Washington
Device: Reader / iPhone / Librie / Kindle
Lightbulb xlets!

I finally figured it out: rather than getting the Java Desktop environment iRex got the Java Microedition Xlet environment from the Tao Group.

Code:
root@ereader:/home/intent# clock.sh
intent (Linux boot loader)
Copyright (c) Tao Systems Ltd 1997-2000

0x564E24 bytes read
Booting image at 0x401ce000-0x405ce400
xlet: ave @ 0x000489a0 [Xlet]
xlet: app @ 0x00026d90
xlet: toolkit @ 0x0001dd80
xlet: vm @ 0x000174d0
xlet: xlet @ 0x00027690
xlet: layout @ 0x000228a8
xlet: dialog @ 0x00027790
Code for clock.sh

Code:
root@ereader:/home/intent# cat clock.sh
#!/bin/sh
EXECPATH=sys/platform/linux/taoref/er10xx
IMGPATH=$EXECPATH
export DISPLAY=:0
export ELATE_FB_TTY=/dev/tty0
#export ELATE_KTRACE=/tmp/ktrace.log
export ELATE_DEBUGSTUB=7990

cd /home/intent/
if [ ! -d /home/intent/ROOTDIR ]
then
   ln -s / ROOTDIR
fi

    OPTIONS="-capp/stdio/xlet /classes/ClockXlet "

exec $EXECPATH/elate -B $IMGPATH/target.img -g2 -l $EXECPATH "$OPTIONS"
An example Xlet

Code:
Macbook-Pro:~/Sources/iliad/xlet scotty$ cat ClockXlet.java 
import javax.microedition.xlet.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class ClockXlet implements Xlet, ActionListener {

    TextField display;
    MyClock clock;
    Button pauseButton = new Button("Pause");
    Button stopButton = new Button("Stop");
    Button resumeButton = new Button("Resume");
    XletContext context;
    public void initXlet(XletContext ctx)
            throws XletStateChangeException {
        Container c;
        context = ctx;
        try {
            c = ctx.getContainer();
        } catch (UnavailableContainerException e) {
            throw new XletStateChangeException(e.getMessage());
        }
        display = new TextField(30);
        clock = new MyClock(display);
        pauseButton.addActionListener(this);
        resumeButton.addActionListener(this);
        resumeButton.setEnabled(false);
        stopButton.addActionListener(this);
        c.setSize(200, 200);
        c.setVisible(true);
        c.add(display);
        c.add(pauseButton);
        c.add(resumeButton);
        c.add(stopButton);
        clock.start();
    }

    public void startXlet() {
        clock.setPaused(false);
        resumeButton.setEnabled(false);
        pauseButton.setEnabled(true);
    }

    public void pauseXlet() {
        clock.setPaused(true);
        resumeButton.setEnabled(true);
        pauseButton.setEnabled(false);
   }

    public void destroyXlet(boolean unconditional) {
        clock.setStopped(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == stopButton) {  
            clock.setStopped(true);
            context.notifyDestroyed();
        } else if (e.getSource() == pauseButton) {
            clock.setPaused(true);
            resumeButton.setEnabled(true);
            pauseButton.setEnabled(false);
            context.notifyPaused();
        } else if (e.getSource() == resumeButton) {
            context.resumeRequest();
        }
    }
}

class MyClock extends Thread {

    boolean paused, stopped;
    TextField display;

    public MyClock(TextField t) {
        display = t;
    }

    String getTime() {
        Calendar rightNow = Calendar.getInstance();
        String hour = String.valueOf(rightNow.get(Calendar.HOUR_OF_DAY));
        String min = String.valueOf(rightNow.get(Calendar.MINUTE));
        if (min.length() == 1) {
            min = "0" + min;
        }
        String sec = String.valueOf(rightNow.get(Calendar.SECOND));
        if (sec.length() == 1) {
            sec = "0" + sec;
        }
        return hour + ":" + min + ":" + sec;
    }

    public synchronized boolean isStopped() {
        return stopped;
    }

    public synchronized void setStopped(boolean value) {
        stopped = value;
        notifyAll();
    }

    public synchronized boolean isPaused() {
        return paused;
    }

    public synchronized void setPaused(boolean value) {
        paused = value;
        notifyAll();
    }

    public void run() {
        while (!isStopped()) {
            try {
                if (!isPaused()) {
                    Thread.sleep(1);
                    display.setText(getTime());
                } else {
                    synchronized (this) {
                        wait();
                    }
                }
            } catch (InterruptedException e) {
            }
        }
    }
}
Compile it

Code:
javac -source 1.2 -target 1.1 -cp ../personal.jar ClockXlet.java
The needed personal.jar can be gotten here: http://java.sun.com/products/persona.../download.html

Pull the crunchy zip apart and the juicy personal.jar core is in the lib directory.

Last edited by scotty1024; 05-15-2007 at 06:18 PM.
scotty1024 is offline   Reply With Quote