package dealertimer.graphics;
import dealertimer.Action;
import dealertimer.Button;
import dealertimer.DealerTimer;
import dealertimer.Point;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
public class TimerCanvas
extends Canvas {
public void start(){
this.start.start();
}
public void run() {
while(true){
try {
if (timer.isEndeed()) {
try {
playTimer();
} catch (MediaException ex) {
ex.printStackTrace();
}
}
ex.printStackTrace();
}
repaint();
}
}
}
private DealerTimer timer;
private Display display;
private Player end;
public TimerCanvas
(Display pDisplay
) throws IOException, MediaException
{
this.timer = new DealerTimer();
this.display = pDisplay;
int buttonSize=this.getWidth()/4;
public void executeCode() {
timer.addMinute();
repaint();
}
}, buttonSize, buttonSize,
"1.MIN",
new Point(0, 4
*(this.
getHeight()/5
)));
public void executeCode() {
timer.start();
if(timer.getStop()){
label="2.START";
}
startStop.setLabel(label);
repaint();
}
}, buttonSize, buttonSize,
"2.START",
new Point(buttonSize, 4
*(this.
getHeight()/5
)));
public void executeCode() {
timer.pause();
if(!timer.getPause()){
label="3.PAUSE";
}
pause.setLabel(label);
repaint();
}
}, buttonSize, buttonSize,
"3.PAUSE",
new Point(2
*buttonSize, 4
*(this.
getHeight()/5
)));
public void executeCode() {
timer.reset();
repaint();
}
}, buttonSize, buttonSize,
"4.RESET",
new Point(3
*buttonSize, 4
*(this.
getHeight()/5
)));
this.end=Manager.createPlayer(getClass().getResourceAsStream("/dealertimer/sounds/timer.wav"), "audio/X-wav");
this.controller.start();
this.setFullScreenMode(true);
}
g.setColor(255, 255, 255);
g.
setFont(Font.
getFont(Font.
FACE_PROPORTIONAL,
Font.
STYLE_BOLD+Font.
STYLE_UNDERLINED,
Font.
SIZE_LARGE));
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(0, 0, 0);
g.drawString("Dealer Timer", (this.getWidth()-g.getFont().stringWidth("Dealer Timer"))/2 , this.getHeight() / 5-g.getFont().getHeight()-3, 0);
g.drawRect(this.getWidth() / 4, this.getHeight() / 5, 2 * (this.getWidth() / 4), this.getHeight() / 5);
g.setColor(0, 200, 90);
g.fillRect((this.getWidth() / 4)+1, (this.getHeight() / 5)+1, (2 * (this.getWidth() / 4))-1, (this.getHeight() / 5)-1);
g.
setFont(Font.
getFont(Font.
FACE_PROPORTIONAL,
Font.
STYLE_BOLD,
Font.
SIZE_LARGE));
if(this.timer.getMinutes()>=10){
time=this.timer.getMinutes()+"";
}else{
time="0"+this.timer.getMinutes();
}
time+=" : ";
if(this.timer.getSeconds()>=10){
time+=this.timer.getSeconds();
}else{
time+="0"+this.timer.getSeconds();
}
g.setColor(0, 0, 0);
g.drawString(time, (this.getWidth()-g.getFont().stringWidth(time))/2, (this.getHeight() / 5)+((this.getHeight()/5)-g.getFont().getHeight())/2, 0);
String level
="Buio: "+this.
timer.
getLevel();
g.drawString(level, (this.getWidth()-g.getFont().stringWidth(level))/2, 2*(this.getHeight() / 5)+((this.getHeight()/5)-g.getFont().getHeight())/2, 0);
g.drawImage(this.addMinute.getGraphics(), this.addMinute.getLocation().x, this.addMinute.getLocation().y, 0);
g.drawImage(this.pause.getGraphics(), this.pause.getLocation().x, this.pause.getLocation().y, 0);
g.drawImage(this.startStop.getGraphics(), this.startStop.getLocation().x, this.startStop.getLocation().y, 0);
g.drawImage(this.reset.getGraphics(), this.reset.getLocation().x, this.reset.getLocation().y, 0);
}
protected void keyPressed(int keyCode) {
this.addMinute.pressButton();
}else if(keyCode
==Canvas.
KEY_NUM2){
this.startStop.pressButton();
}else if(keyCode
==Canvas.
KEY_NUM3){
this.pause.pressButton();
}else if(keyCode
==Canvas.
KEY_NUM4){
this.reset.pressButton();
}
}
protected void pointerPressed(int x, int y) {
if(this.addMinute.isIn(in)){
this.addMinute.pressButton();
}else if(this.startStop.isIn(in)){
this.startStop.pressButton();
}else if(this.pause.isIn(in)){
this.pause.pressButton();
}else if(this.reset.isIn(in)){
this.reset.pressButton();
}
}
public void playTimer() throws MediaException{
this.display.vibrate(1000);
this.end.start();
}
}