import com.nttdocomo.ui.*;
import com.nttdocomo.io.*;
import com.nttdocomo.util.*;

/**
 *
 * Test GC
 *
 * (C) 2001 Beartronics 
 * Author: Henry Minsky (hqm@alum.mit.edu)
 *
 * Licensed under terms "Artistic License"
 * http://www.opensource.org/licenses/artistic-license.html
 *
 */

public class MemTest extends IApplication  implements Runnable {
    MathCanvas c;
    public void start() {
	c = new MathCanvas(this);
	Display.setCurrent(c);
        Thread runner = new Thread(this);
        runner.start();
    }

    public void run() {
	c.count = 0;
        for (;;) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {}

	    String s = new String("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            c.repaint();
	    c.count++;
        }
    }
}

class MathCanvas extends Canvas {
    private IApplication app;

    public int count = 0;

    MathCanvas(IApplication app) {
	this.app = app;
        setSoftLabel(Frame.SOFT_KEY_1, "Exit");
    }

    public void processEvent(int eventType, int param) {
	if (Display.KEY_PRESSED_EVENT == eventType) {
	    switch (param) {
	    case Display.KEY_SELECT:
		Runtime.getRuntime().gc();
		break;
	    }
	}
    }

    void clearScreen (Graphics g) {
	g.setColor(g.getColorOfRGB(0,0,0));
	g.fillRect(0, 0, getWidth(),  getHeight());
    }

    public void paint(Graphics g) {
	g.lock();
	clearScreen(g);
	g.setColor(g.getColorOfRGB(0xff,0,0));
	long free = Runtime.getRuntime().freeMemory();
	long total = Runtime.getRuntime().totalMemory();
	g.drawString("free:  "+free, 10,30);
	g.drawString("total: "+total, 10,45);
	g.unlock(true);
   }

}