Vidya
YaBB Newbies
Offline
Posts: 3
Overloading exit()/super()
Apr 23rd , 2010, 1:13pm
Hello, Below is the code i had written to run a timer and save the data to an xml and an online database before exit. It works perfectly fine when i execute the code from processing but it doesn't work as I export it to window exe. As i run the exe it creates the xml but the code inside exit() is not executed as i close the exe. It would be a great help if anyone can solve this problem Many thanks. /*Code: Using proXML for xml usage*/ import proxml.*; import de.bezier.data.sql.*; PFont font; int currentTimer, seconds,x; XMLInOut xmlIO; proxml.XMLElement system; String uniquetemp, newunique; MySQL msql; void setup(){ background(255, 204, 0); size(550,100); smooth(); x=0; font = loadFont("Swiss721BT-BoldCondensedDType-24.vlw"); xmlIO = new XMLInOut(this); String user = "xxxx"; String pass = "xxxx"; String database = "xxxx"; msql = new MySQL( this, "xxxx", database, user, pass ); try { xmlIO.loadElement("power_saver.xml"); x=1; } catch (Exception e) { xmlEvent(new proxml.XMLElement("system")); proxml.XMLElement power = new proxml.XMLElement("power"); system.addChild(power); newunique = str(int(random(255)))+str(int(random(255)))+str(int(random(255)))+str(int(random (255)))+str(int(random(255))); power.addAttribute("uniqueid", newunique); power.addAttribute("timer", int(millis()/1000)); xmlIO.saveElement(system, "power_saver.xml"); x=0; } } void draw(){ textFont(font); background(255, 204, 0); currentTimer = int(millis()/1000); text("My system is on for : "+currentTimer+" seconds this session", 20, 50); } void xmlEvent(proxml.XMLElement element) { system = element; initPower(); } void initPower() { //system.printElementTree(" "); proxml.XMLElement power; for(int i = 0; i < system.countChildren();i++){ power = system.getChild(i); seconds = power.getIntAttribute("timer"); uniquetemp = power.getAttribute("uniqueid"); println(uniquetemp); } } void updatedb () { if (x==1) { proxml.XMLElement power; power = system.getChild(0); power.addAttribute("timer", seconds+currentTimer); seconds = seconds+currentTimer; xmlIO.saveElement(system, "power_saver.xml"); if ( msql.connect() ) { msql.execute( "update userdata set totaltime = "+seconds+" where uniqueid ="+uniquetemp); } } if (x==0) { proxml.XMLElement power; power = system.getChild(0); power.addAttribute("timer", currentTimer); xmlIO.saveElement(system, "power_saver.xml"); if ( msql.connect() ) { msql.execute( "insert into userdata(uniqueid,totaltime) values("+newunique+","+currentTimer+")" ); } } } public void exit() { updatedb(); super.exit(); }