Does the applet extend "Applet" or "JApplet"? I don't think "Applet" would know enough about Swing components to draw a JPanel properly.
Please use the "CODE" button to surround code of any length with code tags to preserve its formatting.
I'm moving the thread to the AWT/Swing/GUI forum, since there seems to be nothing applet-specific about the question. [ March 07, 2007: Message edited by: Ulf Dittmer ]
The only obvious difficulty is this: When you override the paint method be sure to call super.paint so the JApplet can draw itself and its child components.
A suggestion for graphic components: The JApplet (top–level container) has no way of knowing that the graphic component (RectanglePanel) has custom drawing/graphics on it. It asks RectanglePanel for its display size which is computed by the layout manager (of RectanglePanel) as it lays out the child components. Since it has no children RectanglePanel reports its default (JPanel) size of (10, 10). Being mounted in the center section of a BorderLayout will expand it to fill the available space but if it needs more room it will need to provide a size hint for its parent. You can do this by calling setPreferredSize(Dimension d) inside the class (constructor) or on an instance of the class, ie, RectanglePanel drawpanel in the applet. Or you can override the getPreferredSize method in the class and return the desired Dimension for display. You could move your rects initialization into the constructor and compute the Dimension width and height at the same time.
Rohan Pujari
Greenhorn
Joined: Feb 27, 2007
Posts: 24
posted
0
Thanks for the suggestions.
I have made the layout in the applet as border layout as you can see that i have an important line of code missing
when i added this line to the applet the panel is now being displayed so its working fine thanks for all your help.