import java.awt.Graphics; import javax.swing.JPanel; public class FirstDrawing extends JPanel { public void paintComponent(Graphics g) { //this MUST be the first line in your paintComponent method super.paintComponent(g); final int WIDTH = getWidth(); //getWidth() returns the width of the current panel final int HEIGHT = getHeight(); //getHeight() returns the height of the current panel g.drawLine(0,0, WIDTH,HEIGHT); g.drawLine(0,HEIGHT, WIDTH,0); g.drawLine(WIDTH/2, 0, WIDTH/2, HEIGHT); g.drawLine(0, HEIGHT/2, WIDTH, HEIGHT/2); } //end method paintComponent } //end class FirstDrawing