dis code compiles w/o errors and runs buh doesnt produce d desired effect...its supposed to paint lines like d ones in the picture
Capture.JPG
pls kindly check it out
d DrawPanelTest class just runs d program n displays d DrawPanel, d DrawPanel class is d main problem
import java.awt.Graphics; import javax.swing.JPanel; //modified DrawPanel Class for esercise 4.1 public class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent( g );//pls explain y dis shud ALWAYS be here int width = getWidth(); int height = getHeight(); int widthCounter = 0; int heightCounter = 10; g.drawLine(0,0,width,height); // found out it painted dis line //mayb am wrong buh i fink d probs 4rm here while (widthCounter <= 10) { width = (width*widthCounter)/10; height = (height*heightCounter)/10; g.drawLine(0,0,width,height); ++widthCounter; --heightCounter; } } }
import javax.swing.JFrame; public class DrawPanelTest { public static void main( String args[] ) { DrawPanel panel = new DrawPanel(); JFrame application = new JFrame(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); application.add(panel); application.setSize( 300,300); application.setVisible( true ); } }