This site requires JavaScript, please enable it in your browser!
Greenfoot back
dharmasaputro
dharmasaputro wrote ...

2013/6/20

Java Applet & Frame in Greenfoot

dharmasaputro dharmasaputro

2013/6/20

#
Hello, I'm trying to make a simulator using greenfoot to show an Image Formation by Converging Lenses. I think I'll need to extends my subclasses to java.applet.Applet and Frame (for the lens window). Any idea how to import those Java Applet in greenfoot? Thanks ^^
davmac davmac

2013/6/20

#
I think I'll need to extends my subclasses to java.applet.Applet and Frame (for the lens window)
Are you saying you need two different windows - one showing the Greenfoot world and one showing something else? If so, be aware that Greenfoot isn't really designed to be used with Swing/AWT. You can do it, but doing it properly is very difficult. You must obey both the Swing threading rules and the Greenfoot threading rules - i.e. only call Swing methods from the Swing event dispatch thread, and only call Greenfoot API methods from the Greenfoot simulation thread. If you don't need two different windows, then you don't need to import Applet or Frame.
dharmasaputro dharmasaputro

2013/6/20

#
Thanks Davmac. Yes, I'd like to call Swing methods, in order to show my simulation window. Can I just show the simulation window that calls Swing method?
davmac davmac

2013/6/20

#
I'm still not sure if you need a separate window. When you export a Greenfoot scenario, it already includes an applet window which displays the world. You don't need to write code to do that yourself.
Can I just show the simulation window that calls Swing method?
Sorry, but I don't understand what you mean by that.
dharmasaputro dharmasaputro

2013/6/20

#
well, i referred from this code http://www.phys.hawaii.edu/~teb/java/ntnujava/Lens/thinLens.java. It uses java applet and frame. But when I tried to make it on greenfoot, i got a dialog box saying that "methods in java.awt.Component has been deprecated". So, greenfoot can't uses applet from AWT right? I got confused in how to make such methods (like show() or hide()) and TextField in greenfoot.
davmac davmac

2013/6/20

#
It uses java applet and frame. But when I tried to make it on greenfoot, i got a dialog box saying that "methods in java.awt.Component has been deprecated".
Those methods have been deprecated - the code is old. What you're seeing are warnings, not errors. The box says "Warnings" at the top. It doesn't make sense why you would take that class and compile it (as is) in Greenfoot. The class is an applet. You can have an applet class in your Greenfoot project, but it's useless. You'd be better of using another IDE such as BlueJ.
So, greenfoot can't uses applet from AWT right?
That's not correct. You can use the class, it's just that it is usually pointless. Your Greenfoot scenario is already an applet (when you export it), but you don't have access to the applet instance from within the Greenfoot scenario.
I got confused in how to make such methods (like show() or hide()) and TextField in greenfoot.
The Greenfoot world is not a Swing/AWT component. You can't use things like TextField (from AWT) in it. But there are alternatives which you can find if you search the site for "gui" for example.
You need to login to post a reply.