Code for Lines

 

import java.awt.Graphics;
import java.awt.Color;

public class lines extends
 java.applet.Applet {

  
  public void paint(Graphics g) {



    g.setColor(Color.red);
    g.drawLine(10,200,5,180);
    g.drawLine(10,200,50,200);
    g.drawLine(50,200,50,50);
    g.drawLine(40,50,60,50);






    g.setColor(Color.green);
    g.drawLine(80,200,100,50);
    g.drawLine(100,50,120,200);
    g.drawLine(86,150,114,150);



    g.setColor(Color.yellow);
    g.drawLine(140,50,160,200);
    g.drawLine(160,200,180,50);




    g.setColor(Color.blue);
    g.drawLine(200,200,220,50);
    g.drawLine(220,50,240,200);
    g.drawLine(206,150,234,150);

  }
}
This allows us to use the Graphics methods of the Java Abstract Windowing toolkit.

We want to generate an applet .

The paint method is the way an applet draws objects on the screen.

Select the color red. Draw four lines to create the letter "J". For each line, the first pair of numbers represent the coordinates in pixels (within the applet window) of the first endpoint of the line segment. The second pair of numbers are the coordinates of the second endpoint.

Select the color green and draw three lines to form the letter "A".


.


Select the color yellow and draw two lines to form the letter "V".


.

Select the color blue and draw three lines to form the letter "A".


Back to Lines

Back to the Table of Contents