Story behind this code
It was 2008, July 15th. I compiled my second Java script for my smartphone: Siemens SX1. I had ran it then I saw hundreds of colored rectangles. And then screen of my phone turned off. Forever...
import java.util.Random; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
import javax.microedition.lcdui.Canvas; | |
import javax.microedition.lcdui.Command; | |
import javax.microedition.lcdui.CommandListener; | |
import javax.microedition.lcdui.Display; | |
import javax.microedition.lcdui.Displayable; | |
import javax.microedition.lcdui.Font; | |
import javax.microedition.lcdui.Graphics; | |
import javax.microedition.lcdui.Image; | |
import javax.microedition.midlet.MIDlet; | |
public class TestArea | |
extends MIDlet | |
implements CommandListener | |
{ | |
protected TestArea.MyCanvas myCanvas = new TestArea.MyCanvas(); | |
protected Command quit = new Command("Exit", 7, 1); | |
protected Command redraw = new Command("Redraw", 1, 1); | |
protected Timer timer = new Timer(); | |
protected TestArea.MyTimerTask myTimerTask = new TestArea.MyTimerTask(); | |
public TestArea() | |
{ | |
myCanvas.addCommand(quit); | |
myCanvas.addCommand(redraw); | |
myCanvas.setCommandListener(this); | |
} | |
protected void startApp() | |
{ | |
Display.getDisplay(this).setCurrent(myCanvas); | |
timer.schedule(myTimerTask, 200L, 200L); | |
} | |
protected void pauseApp() {} | |
protected void destroyApp(boolean paramBoolean) {} | |
public void commandAction(Command paramCommand, Displayable paramDisplayable) | |
{ | |
if (paramCommand == redraw) | |
{ | |
myCanvas.repaint(); | |
} | |
else if (paramCommand == quit) | |
{ | |
destroyApp(false); | |
notifyDestroyed(); | |
} | |
} | |
class MyCanvas | |
extends Canvas | |
{ | |
private Random randomiser = new Random(); | |
MyCanvas() {} | |
private int getRand(int paramInt1, int paramInt2) | |
{ | |
int i = Math.abs(randomiser.nextInt()); | |
return i % (paramInt2 - paramInt1) + paramInt1; | |
} | |
protected void paint(Graphics paramGraphics) | |
{ | |
for (int i = 10; i > 0; i--) | |
{ | |
paramGraphics.setGrayScale(getRand(0, 254)); | |
paramGraphics.fillRect(0, 0, i * (getWidth() / 10), i * (getHeight() / 10)); | |
paramGraphics.setStrokeStyle(1); | |
paramGraphics.setColor(255, 255, 255); | |
paramGraphics.setFont(Font.getFont(0, 1, 16)); | |
paramGraphics.drawString("MyDiary v.1.0", 0, getHeight() / 2, 20); | |
Image localImage = null; | |
try | |
{ | |
localImage = Image.createImage("/imageExample.png"); | |
} | |
catch (Exception localException) {} | |
paramGraphics.drawImage(localImage, 0, 0, 20); | |
} | |
} | |
} | |
class MyTimerTask | |
extends TimerTask | |
{ | |
MyTimerTask() {} | |
public void run() | |
{ | |
myCanvas.repaint(); | |
} | |
} | |
} |
It was 2008, July 15th. I compiled my second Java script for my smartphone: Siemens SX1. I had ran it then I saw hundreds of colored rectangles. And then screen of my phone turned off. Forever...