1. /*
  2. * Copyright 1999,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * Created on 2007-1-26
  18. *
  19. */
  20. package peaklau.eaglefund;
  21. import java.util.Calendar;
  22. import javax.microedition.lcdui.Canvas;
  23. import javax.microedition.lcdui.Graphics;
  24. /**
  25. * BaseCanvas class<br>
  26. * The subclasses of this class should overwrite paint() method .<br>
  27. * If the subclasses want to refresh the data, they should overwrite the execute() method. <br>
  28. * @author peaklau <br>
  29. * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
  30. * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
  31. * @version $Revision: 1.2 $ $Date: 2007/10/21 14:26:23 $
  32. */
  33. public class BaseCanvas extends Canvas implements Runnable{
  34. public final static String host="www.peaklau.com";
  35. protected INavigator navigator;
  36. public BaseCanvas(INavigator navigator){
  37. this.navigator=navigator;
  38. }
  39. protected void refresh(){
  40. if(!running){
  41. new Thread(this).start();
  42. }
  43. }
  44. private boolean running=false;
  45. public void run(){
  46. execute();
  47. running=false;
  48. }
  49. /**
  50. * Subclasses can overwrite this method to get refresh some data.
  51. *
  52. */
  53. protected void execute(){
  54. }
  55. protected void paint(Graphics g) {
  56. }
  57. public String getCurrentTime(){
  58. Calendar calendar=Calendar.getInstance();
  59. int year=calendar.get(Calendar.YEAR);
  60. int month=calendar.get(Calendar.MONTH);
  61. int day=calendar.get(Calendar.DAY_OF_MONTH);
  62. int hour=calendar.get(Calendar.HOUR_OF_DAY);
  63. int min=calendar.get(Calendar.MINUTE);
  64. //year+"/"+(month+1)+"/"+day+" "+(hour<10?("0"+hour):(""+hour))+":"+(min<10?("0"+min):(""+min)));
  65. return (hour<10?("0"+hour):(""+hour))+":"+(min<10?("0"+min):(""+min));
  66. }
  67. protected void keyPressed(int keyCode) {
  68. navigator.keyPressed(keyCode);
  69. }
  70. }