| Author |
can rectangle be drawn in jpanel using awt classes
|
kalai sundar
Ranch Hand
Joined: May 25, 2005
Posts: 59
|
|
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.
|
 |
 |
|
|
subject: can rectangle be drawn in jpanel using awt classes
|
|
|