how to use java timer class with laz4android?not TTimer in lazarus lazarus / 43-Android ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 07:12 how to use java timer class with laz4android?not TTimer in lazarus. it is hard to inherited run( ) method.how to do it? need help.. ---------------------------------------------------------------------- Thaddy · 2016-10-14 09:17 I don't use much android, but here is a java example that only uses classes also available to Android (I think); The JLTimerTask.Run method is abstract, so you have to override it, not call inherited on it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program hellojava;{$mode objfpc}{java -cp /usr/local/lib/fpc/3.1.1/units/jvm- java/rtl:. hellojava}{$macro on}{$define writeln:=jlsystem.fout.println}uses jdk15; type  TMyTimerTask = class(JUTimerTask)  private    procedure CompleteTask;  public    constructor Create;    procedure run;override;  end;  procedure TMyTimerTask.run;  begin    writeln('runs ');    CompleteTask;    writeln('Stopped ');  end;     procedure TMyTimerTask.CompleteTask;  begin    JLThread.Sleep(1500);    writeln('Completed');  end;  constructor TMyTimerTask.Create;  begin    inherited;  end;  var Timer: JUtimer;    TimerTask:JUTimerTask; begin  TimerTask := TMyTimerTask.Create;  Timer := JUTimer.Create(true);  timer.scheduleAtFixedRate(timerTask, 0, 1000);  writeln('Freepascal jvm Timer example');  JLThread.Sleep(10000);end. ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 09:40 thank u for the codes,but where to get the jdk15 package for lazarus? ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 09:54 Quote from: Thaddy on October 14, 2016, 11:17:35 amI don't use much android, but here is a java example that only uses classes also available to Android (I think); The JLTimerTask.Run method is abstract, so you have to override it, not call inherited on it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program hellojava;{$mode objfpc}{java -cp /usr/local/lib/fpc/3.1.1/units/jvm- java/rtl:. hellojava}{$macro on}{$define writeln:=jlsystem.fout.println}uses jdk15; type  TMyTimerTask = class(JUTimerTask)  private    procedure CompleteTask;  public    constructor Create;    procedure run;override;  end;  procedure TMyTimerTask.run;  begin    writeln('runs ');    CompleteTask;    writeln('Stopped ');  end;     procedure TMyTimerTask.CompleteTask;  begin    JLThread.Sleep(1500);    writeln('Completed');  end;  constructor TMyTimerTask.Create;  begin    inherited;  end;  var Timer: JUtimer;    TimerTask:JUTimerTask; begin  TimerTask := TMyTimerTask.Create;  Timer := JUTimer.Create(true);  timer.scheduleAtFixedRate(timerTask, 0, 1000);  writeln('Freepascal jvm Timer example');  JLThread.Sleep(10000);end.  ok , i found it.but use this unit it say that "except :, but java.lang found " ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 09:59 Quote from: Thaddy on October 14, 2016, 11:17:35 amI don't use much android, but here is a java example that only uses classes also available to Android (I think); The JLTimerTask.Run method is abstract, so you have to override it, not call inherited on it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program hellojava;{$mode objfpc}{java -cp /usr/local/lib/fpc/3.1.1/units/jvm- java/rtl:. hellojava}{$macro on}{$define writeln:=jlsystem.fout.println}uses jdk15; type  TMyTimerTask = class(JUTimerTask)  private    procedure CompleteTask;  public    constructor Create;    procedure run;override;  end;  procedure TMyTimerTask.run;  begin    writeln('runs ');    CompleteTask;    writeln('Stopped ');  end;     procedure TMyTimerTask.CompleteTask;  begin    JLThread.Sleep(1500);    writeln('Completed');  end;  constructor TMyTimerTask.Create;  begin    inherited;  end;  var Timer: JUtimer;    TimerTask:JUTimerTask; begin  TimerTask := TMyTimerTask.Create;  Timer := JUTimer.Create(true);  timer.scheduleAtFixedRate(timerTask, 0, 1000);  writeln('Freepascal jvm Timer example');  JLThread.Sleep(10000);end.  is it jvm or code for laz4android ---------------------------------------------------------------------- Thaddy · 2016-10-14 11:45 It is generic FPC jvm code and should run on both dalvik and java jvm's. Just use the android library instead of jdk15. On Android you probably want to remove/replace  just the writeln's unless you have a console. The purpose of this code is just to show you how to use a timer and a timertask and do something with it. ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 14:00 thank you,but how about use  jni with lazarus? ---------------------------------------------------------------------- Thaddy · 2016-10-14 14:09 Quote from: greenzyzyzy on October 14, 2016, 04:00:14 pmthank you,but how about use  jni with lazarus? Pas2jni in the utils directory of FPC. But what was the question? You don't need jni for  that, you need a ppcjvm cross-compiler and an installed Android sdk on your development machine. See the wiki.. ---------------------------------------------------------------------- greenzyzyzy · 2016-10-14 14:18 my question is how to use java timer with the example project 'androidlcl' which is  in the lazarus example directory. ---------------------------------------------------------------------- Thaddy · 2016-10-14 15:50 Use my template without the writeln's... And change the uses clause. That's all. AFAIK this is all generic. The documentation is  the Android documentation which says my plan works. [edit] Change the uses clause into androidr15; and my code works, as I expected. ---------------------------------------------------------------------- greenzyzyzy · 2016-10-15 12:11 I still do not know if it can work without jvm or lamw. I only want to use it with the laz4android's default example application in the lazarus's directory juse like I:\laz4android\examples\androidlcl\androidlcltest.lpr will your code can work with it?And how to set your package which is need to use for the project? ---------------------------------------------------------------------- Thaddy · 2016-10-15 13:15 Oh, well, I give up. Maybe somebody will take over after reading the thread. My code works as advertised either with android or java. Skip the writeln's for android and do something else. @greenzyzyzy Plz read the available documentation. That is not hard. All of your questions seem related to one and the same problem: you do not seem to understand the basics. Once you do, this becomes very, very easy. Try to understand the jvm examples and try to understand the laz4android examples. See if you can spot where actual java is called. (hint: jcXxxx) ---------------------------------------------------------------------- greenzyzyzy · 2016-10-15 13:45 thank you ,but would you like to give me the wiki link? ---------------------------------------------------------------------- Thaddy · 2016-10-15 14:28 Quote from: greenzyzyzy on October 15, 2016, 03:45:15 pmthank you ,but would you like to give me the wiki link? No. There's a search feature. ---------------------------------------------------------------------- tintinux · 2016-10-17 08:28 Hi @Thaddy : you are wrong, it is very very difficult to find "the basics" and the search tool do not help much. I you know more than us, please share ! @Greenzyzyzy : if you install and use LAMW, you have a jTimer component working like the TTimer of the LCL. Best regards