Swing (Java): Difference between revisions

Content deleted Content added
Lpurahul (talk | contribs)
mNo edit summary
Window with Button: Improve reference
Line 166:
</syntaxhighlight>
Notice how all instantiation and handling of Swing components are done by creating an instance of the class,
which implements the Runnable interface. This is then run on the [[Event Dispatch Thread]] by use of the method {{Javadoc:SE|member=invokeLater(Runnable)|javax/swing|SwingUtilities|invokeLater(java.lang.Runnable)|module=java.desktop}}), created in the main method (see [[Event dispatching thread#Swing and thread safety|Swing and thread safety]]). Although Swing code can be run without using this technique (for instance, by not implementing Runnable and moving all commands from the run method to the main method), it is considered to be good form, as Swing is not [[Thread safety|thread-safe]], meaning that invoking resources from multiple threads can result in thread interference and memory consistency errors.<ref>http{{Cite web|url=https://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html |title=The Event Dispatch Thread|website=docs.oracle.com}}</ref>
 
===Text Field===