I am unable to upload the project so heres the code.
/**
* Your application code goes here
*/
package userclasses;
import generated.StateMachineBase;
import com.codename1.ui.*;
import com.codename1.ui.events.*;
import com.codename1.ui.list.DefaultListModel;
import com.codename1.ui.util.Resources;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import java.util.Calendar;
/**
*
* @author Your name here
*/
public class StateMachine extends StateMachineBase {
//declaring variable
String source_id;
public Hashtable expTimerTable = new Hashtable();
int threadCnt; double test_time;
public StateMachine(String resFile) {
super(resFile);
// do not modify, write code in initVars and initialize class members there,
// the constructor might be invoked too late due to race conditions that might occur
}
/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
}
@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
final TimeValueForSource tValueSrc = new TimeValueForSource();
threadCnt = threadCnt+1;
System.out.println("SOURCE DETAILS = "+ source_id );
tValueSrc.setSource_id(source_id);
Double t;
t= Double.valueOf(Math.floor(test_time*60));
final long exp_time_in_sec = t.longValue();
final Timer cntDwnTimer = new Timer();
cntDwnTimer.scheduleAtFixedRate(new TimerTask() {
double time_end = exp_time_in_sec * 1000 + System.currentTimeMillis(); ;
double time_remaining = 0;
double time_TenPercent= 0;
TimerUtility timer_Util = new TimerUtility();
public void run() {
// expTimerTable = new Hashtable();
TimerUtility timer = new TimerUtility();
time_remaining = time_end-System.currentTimeMillis();
time_TenPercent = Math.floor(exp_time_in_sec * 1000 * 0.1);
System.out.println("time_TenPercent " + time_TenPercent + "time_remaining " + time_remaining);
if(time_remaining > (time_TenPercent-2000) && time_remaining < time_TenPercent ){
System.out.println(" 10% of the time is remaining!!!!!!! ");
}
if(time_remaining <= 0){
System.out.println(" TIMER UP!!!!! ");
cntDwnTimer.cancel();
}
tValueSrc.setTimeInMs(time_remaining);
tValueSrc.setTimer_Time(timer_Util.onTick(time_remaining));
String st = Thread.currentThread().getName();
System.out.println("st " + st);
// expTimerTable.put("Line1", tValueSrc);
expTimerTable.put(Thread.currentThread().getName(), tValueSrc);
}
}, 10, 1000);
}
@Override
protected void onMain_TextFieldAction(Component c, ActionEvent event) {
TextField tf = findTextField();
test_time = Double.parseDouble(tf.getText());
}
@Override
protected void onMain_ComboBoxAction(Component c, ActionEvent event) {
ComboBox cb = findComboBox();
source_id = cb.getSelectedItem().toString();
}
@Override
protected boolean initListModelMultiList(final com.codename1.ui.List cmp) {
Timer timer = new Timer();
timer.schedule( new TimerTask() {
public void run() {
Hashtable expTimer = expTimerTable;
TimeValueForSource tSrc = new TimeValueForSource();
Vector tList = new Vector();
String keyValForTimer =null;
Enumeration keyEnum = expTimer.keys();
String key1 = (String) keyEnum.toString();
System.out.println("expTimer Key1 = " + key1);
while(keyEnum.hasMoreElements()){
keyValForTimer = (String)keyEnum.nextElement();
System.out.println("keyValForTimer Keys = " + keyValForTimer);
tSrc = (TimeValueForSource)expTimer.get(keyValForTimer);
if(tSrc.getTimeInMs() != 0.0)
tList.add(tSrc.getSource_id() + " " + tSrc.getTimer_Time());
}
cmp.setModel(new com.codename1.ui.list.DefaultListModel(tList));
}
}, 0,1000);
return true;
}
}
TimeValueForSrc
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package userclasses;
/**
*
* @author Shree
*/
public class TimeValueForSource {
private String source, sp_material, source_id ;
private String timer_Time;
private double timeInMs;
private String threadId;
public String getSource(){
return this.source;
}
public String getSp_material(){
return this.sp_material;
}
public String getSource_id(){
return this.source_id;
}
public String getThreadId(){
return this.threadId;
}
public void setThreadId(String threadId){
this.threadId = threadId;
}
public void setSource(String source){
this.source = source;
}
public void setSp_material(String sp_material){
this.sp_material = sp_material;
}
public void setSource_id(String source_id){
this.source_id = source_id;
}
public void setTimer_Time(String timer_Time){
this.timer_Time = timer_Time;
}
public String getTimer_Time(){
return this.timer_Time;
}
public void setTimeInMs(double timeInMs){
this.timeInMs = timeInMs;
}
public double getTimeInMs(){
return this.timeInMs;
}
}
TimerUtility
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package userclasses;
/**
*
* @author Shree
*/
public class TimerUtility {
public String onTick(double millisUntilFinished) {
double hrs=0;
long hrs_rounded = 0;
double mnts=0;
long mnts_rounded =0;
double scnds=0;
long scnds_rounded=0;
scnds=(millisUntilFinished/1000);
if(scnds > 59){
scnds_rounded = Double.valueOf(Math.floor(scnds%60)).longValue();
}
else{
scnds_rounded = Double.valueOf(Math.floor(scnds)).longValue();
}
if (scnds>59) {
mnts=(scnds/60);
mnts_rounded = Double.valueOf(Math.floor(mnts)).longValue();
if (mnts_rounded <= 0) {
mnts=0;
}
}
if (mnts>59) {
hrs=(mnts/60);
hrs_rounded = Double.valueOf(Math.floor(hrs)).longValue();
if (hrs <=0) {
hrs=0;
}
}
String disHour = (hrs_rounded < 10 ? "0" : "") + hrs_rounded,
disMinu = (mnts_rounded < 10 ? "0" : "") + mnts_rounded ,
disSec = (scnds_rounded < 10 ? "0" : "") + scnds_rounded ;
return disHour + ":" + disMinu + ":" + disSec;
}
}