Whether or not you execute this code on the EDT will do nothing to your label. It is not because you increment x
that the label will update itself. You need to call label#setText
with the updated value.
Concerning your question around the EDT. All access/modifications/creation/... of Swing components should happen on the EDT. This means you should wrap the contents of your main method in an SwingUtilities#invoke...
. Every event that is triggered through the UI (e.g. the click on a button) will already be processed on the EDT. So no need to explicitly schedule a Runnable
on the EDT in your listener.
When in doubt, you can always check whether you are on the EDT by using EventQueue#isDispatchThread
.
I would also suggest to read the Concurrency in Swing tutorial