drawLine to write text MF
I am trying to make the letters MF using drawLine, but is struggling to connect the lines
public void paintComponent (Graphics g)
{
// Render the image.
g.drawImage (image, 30,30, this);
// INSERT YOUR CODE HERE:
// Do your graffitti here. For example,
g.drawLine(150,100,150,140);
g.drawLine(150,0,150,0);
}
You can take advantage of drawString
:
g.drawImage (image, 30,30, this);
//set font size (optional)
Font font = g.getFont().deriveFont( 20.0f );
g.setFont( font );
g.drawString("MF", 150, 100);
If you want to draw it line by line :
//draw M
g.drawLine(150,100,150,140); //from top left vertically down
g.drawLine(150,100,165,115); //from top left diagonally dowm
g.drawLine(165,115,180,100); //continue diagonally up
g.drawLine(180,100,180,140); //continue vertically down
//todo draw F
From the documentation:
Draws a line, using the current color, between the points (x1, y1) and (x2, y2)in this graphics context's coordinate system.
so g.drawLine(150,0,150,0)
draws a line between the same points (point 150,0 to point 150,0) which means it draws a point rather than a line.