File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can rectangle be drawn in jpanel using awt classes

 
kalai sundar
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic