Sign in to follow this  

[java] swing and awt

This topic is 3501 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 know there are problems mixing the two, so i want to try to use one. Id like to use swing as its lightweight, but I personally find awt has many essential parts to it. Such as setLayout(), setSize(), Graphics component, etc. Are there elements to swing that contains similar objects, or should I perhaps switch to using just awt.

Share this post


Link to post
Share on other sites
Quote:
Original post by agm_ultimatex
I know there are problems mixing the two, so i want to try to use one. Id like to use swing as its lightweight, but I personally find awt has many essential parts to it. Such as setLayout(), setSize(), Graphics component, etc. Are there elements to swing that contains similar objects, or should I perhaps switch to using just awt.


The Swing components all extend from AWT components. So setLayout(), setSize(), the Graphics object, and other AWT idioms are used in Swing as well. In general, Swing should always be preferred over AWT.

Share this post


Link to post
Share on other sites
Quote:
Original post by agm_ultimatex
i realized that about setSize(). However eclipse gives me compile errors with setLayout and Graphics, unless of course i import java.awt.*


The problem with mixing AWT and Swing usually only pops up when mixing Components -- like mixing JMenus and Panels, the JMenu will not draw correctly over the Panel -- and not with the stuff that you're worrying about. You should be fine with using setLayout and Graphics in Swing.

If you plan on doing active rendering, however, you may want to use AWT instead of Swing, just because it is easier to get working correctly.

Greggles

Share this post


Link to post
Share on other sites
Quote:
Original post by agm_ultimatex
I can't say for sure as I lost all my school stuff. But I think when we did java gui, we used a regular Frame, JPanels, Jtextfields and all other J-Containers.

Yeah, certain things do work together just fine (as far as I know what you are saying may work without any problems), but I guess the idea is that, when possible, you should try to keep your entire program consistant. The only problem is that sometimes you need to use certain AWT stuff with Swing [smile] So, don't worry about importing things like Graphics and Layouts, those should be fine.

Greggles

Share this post


Link to post
Share on other sites
Quote:
Original post by agm_ultimatex
i realized that about setSize(). However eclipse gives me compile errors with setLayout and Graphics, unless of course i import java.awt.*


When you use setLayout you might be doing something like this:

setLayout(new BorderLayout());



All the original layout managers are in the java.awt package. That is why you still have to import it.

You should also try to not use global imports like java.awt.*, you should instead specify each class that you want to import. This will help you understand where things are coming from so you can avoid misunderstandings like this in the future.


[Edited by - CaptainJester on May 25, 2008 7:06:22 AM]

Share this post


Link to post
Share on other sites
When I was playing with GL for Java, I had to use AWT heavyweight componant. But One in one of these panel, I put all that is needed to be able to use Swing component

Share this post


Link to post
Share on other sites

This topic is 3501 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this