Login    New User    Forgot Password    Help      

Lines And Shapes

Java Tutorials

Example

// lines and shapes

import java.awt.*;
import java.applet.*;
/* applet code ="app1" width =300 height = 300>
</applet>
*/
import java.awt.Graphics;

public class app3 extends java.applet.Applet
{
public void paint(Graphics g)
{
// rectanlge
g.setColor(Color.green);
g.drawRect(50,50,200,200);

// rounded rectangle
g.setColor(Color.black);
g.drawRoundRect(53,53,197,197,10,10);

// fill
g.setColor(Color.gray);
g.fillRoundRect(53,53,197,197,10,10);

// three dimnetional rectangle
g.setColor(Color.black);
// with very small effect
g.draw3DRect(40,40,220,220,true);
g.draw3DRect(40,40,220,220,false);

// polygon
int exes[] = { 39,94,97,142,53,58,26 };
int whys[] = { 33,74,36,70,108,80,106 };
int pts = exes.length;
g.drawPolygon(exes,whys,pts);

// declaring polygon as object
Polygon poly = new Polygon(exes,whys,pts);
g.setColor(Color.red);
g.fillPolygon(poly);


// ovel
g.drawOval(220,20,60,60);
g.fillOval(220,20,60,60);

// Arcs
g.drawArc(20,220,60,60,90,180);
g.fillArc(20,220,60,60,90,180);

// lines
g.setColor(Color.red);
g.drawLine(25,25,75,75);

}
}

Output

Output in applet

Java Tutorials