drawLine()

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

Color.magenta is the closest to purple.

drawLine()

line on grid paper

 

To draw a line on the Graphics object, use:

drawLine(int x1, int y1, int x2, int y2)

This draws a line from (x1, y1) to (x2, y2) in the drawing area using the current pen color. As usual, the point (0,0) is the upper left corner of the drawing area.

It doesn't matter in which direction you draw the line. The end and the start of the line could be reversed.

QUESTION 18:

Say that the Graphics object grph has a drawing area of width=200 and height=150. Fill in the blanks to draw a line from the lower left corner to the upper right corner of the area.

grph.drawLine( , , ,  )