This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes can rectangle be drawn in jpanel using awt classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "can rectangle be drawn in jpanel using awt classes" Watch "can rectangle be drawn in jpanel using awt classes" New topic
Author

can rectangle be drawn in jpanel using awt classes

kalai sundar
Ranch Hand

Joined: May 25, 2005
Posts: 69
i am desgning the container ship blocks, Then i tried with awt classes, vat i did is ,

new JPanel(){
public void paint(Graphics g){
for( int i = 1; i <=100 ; i++){
if( i <= 10 )
g.fillRect(i*10, 10, 8, 8);
else if( i > 10 && i <= 20)
g.fillRect((i-10)*10, 20, 8, 8);
else if( i > 20 && i <= 30 )
g.fillRect((i-20)*10, 30, 8,8);
else if( i > 30 && i <= 40 )
g.fillRect((i-30)*10, 40, 8,8);
else if( i > 40 && i <= 50 )
g.fillRect((i-40)*10, 50, 8,8);
else if( i > 50 && i <= 60 )
g.fillRect((i-50)*10, 60, 8,8);
else if( i > 60 && i <= 70 )
g.fillRect((i-60)*10, 70, 8,8);
else if( i > 70 && i <= 80 )
g.fillRect((i-70)*10, 80, 8,8);
else if( i > 80 && i <= 90 )
g.fillRect((i-80)*10, 90, 8,8);
else if( i > 90 && i <= 100 )
g.fillRect((i-90)*10, 100, 8,8);






}

}

};

i placed this code in custome creation code,But if i do write as seperate method, and i am calling the method, the rectangle r not drawn in jpanel.vat should i do?Help me?
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
because here you are using anonymous class and your graphics is drwan over that anonymous class object. anonymous class object does not have existance without the object of enclosing class.
 
Don't get me started about those stupid light bulbs.
 
subject: can rectangle be drawn in jpanel using awt classes
 
Similar Threads
Strange behavior for enhanced ForLoop.
Whats wrong with system.err?
A Hard Puzzle
How would i shuffle my deck of cards?
Displaying a histogram using input from an array