Main.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package weerstation;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Timer;
  6. import java.util.TimerTask;
  7. public class Main {
  8. static Weerstation weerstation1;
  9. static Measurement meting1;
  10. static ArrayList<Measurement> meting2;
  11. public static void main(String[] args){
  12. weerstation1 = new Weerstation();
  13. meting1 = weerstation1.getMostRecentMeasurement();
  14. meting2 = weerstation1.getAllMeasurementsLast24h();
  15. IO.init();
  16. Timer timer = new Timer();
  17. //All the different screen classes
  18. final List<Object> lstScreens = new ArrayList<Object>();
  19. lstScreens.add(new AvgWindspeed(meting1, meting2, 1));
  20. //Screen switcher
  21. timer.scheduleAtFixedRate(new TimerTask() {
  22. public void run() {
  23. }
  24. }, 0, 15*1000);
  25. //Update recent measurement every 60 seconds
  26. timer.scheduleAtFixedRate(new TimerTask() {
  27. public void run() {
  28. meting1 = weerstation1.getMostRecentMeasurement();
  29. for(Object obj : lstScreens){
  30. try {
  31. obj.getClass().getMethod("updateRecent", Measurement.class).invoke(obj, meting1 );
  32. } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }
  37. }, 60*1000, 60*1000);
  38. //Update 24hours every 60 seconds
  39. timer.scheduleAtFixedRate(new TimerTask() {
  40. public void run() {
  41. meting2 = weerstation1.getAllMeasurementsLast24h();
  42. for(Object obj : lstScreens){
  43. try {
  44. obj.getClass().getMethod("update24Hour", ArrayList.class).invoke(obj, meting2 );
  45. } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
  50. }, 10*60*1000, 10*60*1000);
  51. //Button checker
  52. timer.scheduleAtFixedRate(new TimerTask() {
  53. public void run() {
  54. }
  55. }, 0, 60*1000);
  56. }
  57. }