MainComponent.cpp
#include "MainComponent.h"
//==============================================================================
MainComponent::MainComponent()
{
setSize (600, 400);
addAndMakeVisible(checkTimeButton);
addAndMakeVisible(timeLabel);
checkTimeButton.onClick() = [this] () {checkTimeFunction(); };
currentTime = juce::Time::getCurrentTime();
lastTime = currentTime;
}
MainComponent::~MainComponent()
{
}
void MainComponent::checkTimeFunction() {
currentTime = juce::Time::getCurrentTime();
juce::RelativeTime timeDifference = (currentTime - lastTime);
timeLabel.setText(juce::String(timeDifference.inMilliseconds()) + " milliseconds", juce::dontSendNotification);
lastTime = currentTime;
}
//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
}
void MainComponent::resized()
{
// This is called when the MainComponent is resized.
// If you add any child components, this is where you should
// update their positions.
}
MainComponent.h
#pragma once
#include <JuceHeader.h>
//==============================================================================
/*
This component lives inside our window, and this is where you should put all
your controls and content.
*/
class MainComponent : public juce::Component
{
public:
//==============================================================================
MainComponent();
~MainComponent() override;
//==============================================================================
void paint (juce::Graphics&) override;
void resized() override;
void checkTimeFunction();
private:
//==============================================================================
// Your private member variables go here...
juce::TextButton checkTimeButton;
juce::Label timeLabel;
juce::Time currentTime = juce::Time::getCurrentTime();
juce::Time lastTime = currentTime;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
I didn’t add any ‘void’

