Updating swing components from an arbitrary thread

Rated 4.54/5 based on 564 customer reviews

DISPOSE_ON_CLOSE); set Visible(true); add Key Listener(this); new Thread(this).start(); public void key Pressed(Key Event event) //synchronized(this) is Key Down = true; public void key Released(Key Event event) //synchronized(this) is Key Down = false; public void key Typed(Key Event event) public void run() // game loop while(true) //synchronized(this) boolean cache = is Key Down; print(is Key Down); // before print(' '); /* event handling, game logic, etc.

However, people generally expect their applications to have a consistent look and feel and that is usually different on different platforms.Working with user interface components in Swing is meant to be easy.When building a user interface for your application, you’ll be working with a large set of prefabricated components.Working purely in Java makes Swing much less prone to platform-specific bugs, which were a problem for AWT.It also means that Swing components are much more flexible and can be extended and modified in your applications in ways that native components could never be.

Leave a Reply