GridBagLayout and Graphics2D Problem.

Hello@all. For an universitary project In java we have to code a game.

We can only use the default Java (JRE) classes non extra ones.

So i have to use a Java Standard LayoutManager i decided for the GridBagLayout.

We have an Menu, a toolbar north, a toolbar west and in the “south” of the Frame we have an txtChatBox.

In the Middle we want to put the 2D-Tilesgame. But it doesn’t works. Eclipse says, that Gridbag needs an component and not a Graphics2D?

Sorry that I can’t post sourcecode since this would be against the rules of the Project.

THX for your help!

Ps3udo

can you motivate your choise to go with a gridbaglayout.?

a layout has nothing to do with painting, as it lines out/positions components or an container and doesn’t get any call directly or indirectly wenn it’s time to paint. Layout managers act up wenn resize reposition or wenn components are added removed.(where the latter 2 have some special cases.) (Layout changes do useally cause repaints).

a graphics object is an abstract reprentation of a graphics context. components paint themself to a context. and you as a developer only handle components you don’t really deal with the graphics context in an abstract sense you do deal with it but thats because paint() is part of a call back meganism.

Hi,
You need to put a subclass of a java.awt.Canvas or javax.swing.JPanel, In this you render your graphics
using active rendering or overriding the paint()/paintComponent() methods.

Rafael.-