Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

Unity [java] Please explain this Java code to me.

This topic is 3505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to learn Java right now and the only time I’ve ever used it was in a small intro course at a community college a few years ago. I am experimenting with NetBeans right now and it generated the following code:
  

        jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddActionPerformed(evt);
            }
        });

What exactly is going on here? Is it looks like it is creating a temporary derived class and overriding the constructor and the actionPerformed function. Is that what is going on? Also, is there an easy way I can run non applet Java programs without having to use the Command Prompt or the IDE?

Share this post


Link to post
Share on other sites
Advertisement
Quote:

What exactly is going on here?


It is creating a new ActionListener object, and overriding the actionPerformed method, then passing the newly created object to the addActionListener method. The other option would be to simply create an entire new class extending the ActionListener object and overriding the actionPerformed method, then creating a new instance of the object to pass to addActionListener. However, if you used this method with several different buttons, you would need to create separate classes for each one, which would create more unnecessary code and clutter.

Share this post


Link to post
Share on other sites
Quote:
Original post by ManaStone
Also, is there an easy way I can run non applet Java programs without having to use the Command Prompt or the IDE?


Assuming you mean desktop applications:

1. Make a batch file (.bat or .sh) containing the command (either java <class> or java -jar <jarfile>
2. Make an executable jar, which at least on windows can be executed on double click (if you assigned 'java.exe' to the '.jar' extension).

The same is true for command line applications, but you wouldn't get the output. ;)

For other application types (JEE components, Midlets, Servlets, ...) there are other ways. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!