104 Program to draw triangle in Applet in Java

Code:

import java.awt.*;
import java.applet.*;
/*
<applet code="First" height=300 width=300>
</applet>
*/
public class First extends Applet
{
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
}

public void paint(Graphics g)
{
g.drawLine(30,150,70,150); // (x1,y1,x2,y2) (left,top,left,top)
g.drawLine(50,50,30,150);
g.drawLine(50,50,70,150);
}
}





Ouput:


Draw Triangle in Java

Previous
Next Post »