classdef app_3_5_2 < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure      matlab.ui.Figure
    SekundeLabel  matlab.ui.control.Label
    MinuteLabel   matlab.ui.control.Label
    StundeLabel   matlab.ui.control.Label
    UhrzeitLabel  matlab.ui.control.Label
  end

  
  properties (Access = private)
    Timer  % Timer für Uhrzeit
  end
  
  methods (Access = private)
    
    function results = zeigeZeit(app)
      results = 0;
      d = datetime("now");  % Computerzeiz holen 
      h = num2str( hour(d) );
      m = num2str( minute(d) );
      s = num2str( floor( second(d) ) );
      % in die Felder eintragen 
      app.StundeLabel.Text = h;
      app.MinuteLabel.Text = m;
      app.SekundeLabel.Text = s;
    end
    
    function results = LoopFnc(app, obj, event, string_arg)
      results = zeigeZeit(app);
    end
  end
  

  % Callbacks that handle component events
  methods (Access = private)

    % Code that executes after component creation
    function startupFcn(app)
      zeigeZeit( app );
      % Timer starten
      app.Timer = timer('Name','Timer', ...
                  'Period', 1, ...
                  'BusyMode', 'queue', ...
                  'StartDelay', 1,... 
                  'ExecutionMode', 'fixedrate',...
                  'TimerFcn', @app.LoopFnc );
      start( app.Timer );     % Timer starten 
    end

    % Close request function: UIFigure
    function UIFigureCloseRequest(app, event)
      stop(app.Timer);         % Timer stoppen 
      delete(app.Timer);       % Timer löschen 
      delete(app);
    end
  end

  % Component initialization
  methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

      % Create UIFigure and hide until all components are created
      app.UIFigure = uifigure('Visible', 'off');
      app.UIFigure.Position = [100 100 298 127];
      app.UIFigure.Name = 'MATLAB App';
      app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);

      % Create UhrzeitLabel
      app.UhrzeitLabel = uilabel(app.UIFigure);
      app.UhrzeitLabel.Position = [118 75 100 22];
      app.UhrzeitLabel.Text = 'Uhrzeit';

      % Create StundeLabel
      app.StundeLabel = uilabel(app.UIFigure);
      app.StundeLabel.HorizontalAlignment = 'center';
      app.StundeLabel.Position = [65 39 43 22];
      app.StundeLabel.Text = 'Stunde';

      % Create MinuteLabel
      app.MinuteLabel = uilabel(app.UIFigure);
      app.MinuteLabel.HorizontalAlignment = 'center';
      app.MinuteLabel.Position = [119 39 41 22];
      app.MinuteLabel.Text = 'Minute';

      % Create SekundeLabel
      app.SekundeLabel = uilabel(app.UIFigure);
      app.SekundeLabel.HorizontalAlignment = 'center';
      app.SekundeLabel.Position = [172 39 52 22];
      app.SekundeLabel.Text = 'Sekunde';

      % Show the figure after all components are created
      app.UIFigure.Visible = 'on';
    end
  end

  % App creation and deletion
  methods (Access = public)

    % Construct app
    function app = app_3_5_2

      % Create UIFigure and components
      createComponents(app)

      % Register the app with App Designer
      registerApp(app, app.UIFigure)

      % Execute the startup function
      runStartupFcn(app, @startupFcn)

      if nargout == 0
        clear app
      end
    end

    % Code that executes before app deletion
    function delete(app)

      % Delete UIFigure when app is deleted
      delete(app.UIFigure)
    end
  end
end