classdef app_3_2_1 < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure             matlab.ui.Figure
    SliderwertEditField  matlab.ui.control.NumericEditField
    SliderValLabel_2     matlab.ui.control.Label
    SliderValLabel       matlab.ui.control.Label
    FarbLabel            matlab.ui.control.Label
    ButtonGroup          matlab.ui.container.ButtonGroup
    blauButton           matlab.ui.control.RadioButton
    grnButton            matlab.ui.control.RadioButton
    rotButton            matlab.ui.control.RadioButton
    Slider               matlab.ui.control.Slider
    SliderLabel          matlab.ui.control.Label
    ItemLabel            matlab.ui.control.Label
    ListBox              matlab.ui.control.ListBox
    ListBoxLabel         matlab.ui.control.Label
  end

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

    % Code that executes after component creation
    function startupFcn(app)
      app.ListBox.Value = 'Item 3';
      butt = app.ButtonGroup.Buttons(3);
      app.blauButton.Value = 1;
    end

    % Value changed function: ListBox
    function ListBoxValueChanged(app, event)
      value = app.ListBox.Value;
      app.ItemLabel.Text = value + " gewählt";
    end

    % Value changed function: Slider
    function SliderValueChanged(app, event)
      value = app.Slider.Value;
      app.SliderValLabel.Text = "W = " + num2str( value );
      app.SliderwertEditField.Value = value;
    end

    % Selection changed function: ButtonGroup
    function ButtonGroupSelectionChanged(app, event)
      selectedButton = app.ButtonGroup.SelectedObject;
      app.FarbLabel.Text = "Wahl = " + selectedButton.Text;
    end

    % Value changed function: SliderwertEditField
    function SliderwertEditFieldValueChanged(app, event)
      value = app.SliderwertEditField.Value;
      app.SliderValLabel.Text = "W = " + num2str( value );
      app.Slider.Value = value;
    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 372 368];
      app.UIFigure.Name = 'MATLAB App';

      % Create ListBoxLabel
      app.ListBoxLabel = uilabel(app.UIFigure);
      app.ListBoxLabel.HorizontalAlignment = 'right';
      app.ListBoxLabel.Position = [47 303 48 22];
      app.ListBoxLabel.Text = 'List Box';

      % Create ListBox
      app.ListBox = uilistbox(app.UIFigure);
      app.ListBox.ValueChangedFcn = createCallbackFcn(app, @ListBoxValueChanged, true);
      app.ListBox.Position = [110 253 100 74];

      % Create ItemLabel
      app.ItemLabel = uilabel(app.UIFigure);
      app.ItemLabel.BackgroundColor = [0.8 0.8 0.8];
      app.ItemLabel.HorizontalAlignment = 'center';
      app.ItemLabel.Position = [242 282 104 22];
      app.ItemLabel.Text = 'gewähltes Item';

      % Create SliderLabel
      app.SliderLabel = uilabel(app.UIFigure);
      app.SliderLabel.HorizontalAlignment = 'right';
      app.SliderLabel.Position = [48 204 36 22];
      app.SliderLabel.Text = 'Slider';

      % Create Slider
      app.Slider = uislider(app.UIFigure);
      app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
      app.Slider.Position = [105 213 150 3];

      % Create ButtonGroup
      app.ButtonGroup = uibuttongroup(app.UIFigure);
      app.ButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @ButtonGroupSelectionChanged, true);
      app.ButtonGroup.Title = 'Button Group';
      app.ButtonGroup.Position = [49 47 123 106];

      % Create rotButton
      app.rotButton = uiradiobutton(app.ButtonGroup);
      app.rotButton.Text = 'rot';
      app.rotButton.Position = [11 60 58 22];
      app.rotButton.Value = true;

      % Create grnButton
      app.grnButton = uiradiobutton(app.ButtonGroup);
      app.grnButton.Text = 'grün';
      app.grnButton.Position = [11 38 65 22];

      % Create blauButton
      app.blauButton = uiradiobutton(app.ButtonGroup);
      app.blauButton.Text = 'blau';
      app.blauButton.Position = [11 16 65 22];

      % Create FarbLabel
      app.FarbLabel = uilabel(app.UIFigure);
      app.FarbLabel.BackgroundColor = [0.8 0.8 0.8];
      app.FarbLabel.HorizontalAlignment = 'center';
      app.FarbLabel.Position = [209 86 110 22];
      app.FarbLabel.Text = 'gewählte Farbe';

      % Create SliderValLabel
      app.SliderValLabel = uilabel(app.UIFigure);
      app.SliderValLabel.Position = [279 194 76 22];
      app.SliderValLabel.Text = 'Slider';

      % Create SliderValLabel_2
      app.SliderValLabel_2 = uilabel(app.UIFigure);
      app.SliderValLabel_2.HorizontalAlignment = 'right';
      app.SliderValLabel_2.Position = [212 145 58 22];
      app.SliderValLabel_2.Text = 'Sliderwert';

      % Create SliderwertEditField
      app.SliderwertEditField = uieditfield(app.UIFigure, 'numeric');
      app.SliderwertEditField.Limits = [0 100];
      app.SliderwertEditField.ValueChangedFcn = createCallbackFcn(app, @SliderwertEditFieldValueChanged, true);
      app.SliderwertEditField.Position = [279 145 50 22];

      % 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_2_1

      % 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