Pages

Wednesday, May 25, 2011

My first Java Graphics Program!!

import acm.program.*;
import acm.graphics.*;
import java.awt.*;

public class jav extends GraphicsProgram
{
public void run()
{
GLabel lab=new GLabel("Hello World",50,50);//Creates a text label
add(lab);
GRect rect=new GRect(10,10,30,30);//Creates a rectangle, rect
rect.setFilled(true);
rect.setFillColor(Color.red);//Fills red color inside the rect
add(rect);
GOval ov=new GOval(10,10,30,30);//Creates an oval ov(inside rect)
ov.setFilled(true);
ov.setFillColor(Color.green);//green color inside ov
add(ov);
GLine li=new GLine(60,60,80,80);//Creates a new Line, li
li.setColor(Color.cyan);//cyan colored line
add(li);
}
}



No comments:

Post a Comment