user3876042
user3876042

Reputation: 15

Stuck on Java 2D beginners tutorial

I'm new to Java and I'm trying use Java 2D to try to get familiar with the language. I did the same thing with Python/Pygame to make simple games (snake, minesweeper etc) without too much struggle, but Java 2D seems a whole lot more complicated.

I'm following the tutorial on this site, but in the SimpleEx.java code example I can't figure out what's going on:

EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            BasicEx ex = new BasicEx();
            ex.setVisible(true);
        }
});

It looks like a new method is being declared inside the .invokeLater() method call. Is this run() method a separate argument being passed into invokeLater()? Or is it adding this method to the new Runnable() object before the object is passed into the method?

Upvotes: 0

Views: 252

Answers (1)

itwasntme
itwasntme

Reputation: 1462

run() is main method of runnable interface. In invokeLater() you pass new Runnable object which has to implement its own run() method. So what you do currently is creating anonymous Runnable class and passing it into EventQueue method. This way of running GUI applications starts your APP in separate thread using provided run() method and is used for concurrency reasons - like to not to block GUI on others background operations

Upvotes: 3

Related Questions