1.Drawing Line,Rectangle,Oval(Circle) Applet Graphics in JAVA.Radius of Circle is r=225 & diameter d=450.
CODING:
import java.applet.*;
import java.awt.*;
/*<applet code="ci" width=455 height=455></applet>*/
public class ci extends Applet
{
public void paint(Graphics g)
{
g.drawOval(0,0,450,450); //1 public void drawOval(int x,int y,int width,int height);
g.drawLine(225,0,225,450); //2 public void drawLine(int x1,int y1,int x2,int y2);
g.drawLine(0,225,450,225); //3 number of line (0,radius,diameter,radius)
g.drawLine(225,0,0,225); //4 number of line (radius,0,0,radius)
g.drawLine(0,225,225,450); //5 number of line (0,radius,radius,diameter)
g.drawLine(225,450,450,225); //6 number of line (radius,diameter,diameter,radius)
g.drawLine(450,225,225,0); //7 number of line (diameter,radius,radius,0)
g.drawRect(112,112,225,225); //8 public void drawRect(int x,int y,int width,int height); (radius/2,radius/2,radius,radius)
g.fillRoundRect(215,102,20,20,2,2); //9 public void fillRoundRect(int x,int y,int width,int height,int arcw,int arch);
g.fillRoundRect(102,215,20,20,2,2); //10 (radius/2-(width/2),radius-(height/2),width,height,arcw,arch);
g.fillRoundRect(215,327,20,20,2,2); //11 (radius-(height/2),radius+radius/2-(width/2),...)
g.fillRoundRect(327,215,20,20,2,2); //12
g.fill3DRect(210,210,30,30,true); //13 public void fill3DRect(int x,int y,int width,int height,boolean raised);
g.drawLine(337,112,112,337); //14 (radius+radius/2,radius/2,radius/2,radius+radius/2)
g.drawLine(112,112,337,337); //15 (radius/2,radius/2,radius+radius/2,radius+radius/2)
g.fillOval(56,56,20,20); //17 public void fillOval(int x,int y,int width,int height);
g.fillOval(56,374,20,20); //18 (radius/4,diameter-(radius/4)-height,int width,int height);
g.fillOval(374,374,20,20); //19 (diameter-(radius/4)-width,diameter-(radius/4)-width,int width,int height);
g.fillOval(374,56,20,20); //20 (diameter-(radius/4)-width,radius/4,int width,int height);
//all functions have int data type of argument.
}
}
import java.awt.*;
/*<applet code="ci" width=455 height=455></applet>*/
public class ci extends Applet
{
public void paint(Graphics g)
{
g.drawOval(0,0,450,450); //1 public void drawOval(int x,int y,int width,int height);
g.drawLine(225,0,225,450); //2 public void drawLine(int x1,int y1,int x2,int y2);
g.drawLine(0,225,450,225); //3 number of line (0,radius,diameter,radius)
g.drawLine(225,0,0,225); //4 number of line (radius,0,0,radius)
g.drawLine(0,225,225,450); //5 number of line (0,radius,radius,diameter)
g.drawLine(225,450,450,225); //6 number of line (radius,diameter,diameter,radius)
g.drawLine(450,225,225,0); //7 number of line (diameter,radius,radius,0)
g.drawRect(112,112,225,225); //8 public void drawRect(int x,int y,int width,int height); (radius/2,radius/2,radius,radius)
g.fillRoundRect(215,102,20,20,2,2); //9 public void fillRoundRect(int x,int y,int width,int height,int arcw,int arch);
g.fillRoundRect(102,215,20,20,2,2); //10 (radius/2-(width/2),radius-(height/2),width,height,arcw,arch);
g.fillRoundRect(215,327,20,20,2,2); //11 (radius-(height/2),radius+radius/2-(width/2),...)
g.fillRoundRect(327,215,20,20,2,2); //12
g.fill3DRect(210,210,30,30,true); //13 public void fill3DRect(int x,int y,int width,int height,boolean raised);
g.drawLine(337,112,112,337); //14 (radius+radius/2,radius/2,radius/2,radius+radius/2)
g.drawLine(112,112,337,337); //15 (radius/2,radius/2,radius+radius/2,radius+radius/2)
g.fillOval(56,56,20,20); //17 public void fillOval(int x,int y,int width,int height);
g.fillOval(56,374,20,20); //18 (radius/4,diameter-(radius/4)-height,int width,int height);
g.fillOval(374,374,20,20); //19 (diameter-(radius/4)-width,diameter-(radius/4)-width,int width,int height);
g.fillOval(374,56,20,20); //20 (diameter-(radius/4)-width,radius/4,int width,int height);
//all functions have int data type of argument.
}
}
2.Circle divided to 360 Degree Applet JAVA.
CODING:
/*<applet code="de" width=455 height=455>
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class de extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(x,0,y,R*2);
g.drawLine(0,y,R*2,x);
y-=R/45;
}
}
}
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class de extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(x,0,y,R*2);
g.drawLine(0,y,R*2,x);
y-=R/45;
}
}
}
3.Draw a Graph,Each box is 6 pixel and draw a circle in Applet JAVA.
CODING:
/*<applet code="b" width=455 height=455>
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class b extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(0,x,R*2,x);
g.drawLine(x,0,x,R*2);
}
}
}
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class b extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(0,x,R*2,x);
g.drawLine(x,0,x,R*2);
}
}
}
4.Draw a Graph,Each box is 6 pixel and draw a Circle divided to 360 Degree Applet JAVA.
CODING:
/*<applet code="b" width=455 height=455>
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class b extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(x,0,y,R*2);
g.drawLine(0,y,R*2,x);
y-=R/45;
}
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(0,x,R*2,x);
g.drawLine(x,0,x,R*2);
}
}
}
<param name="radius" value="270">
</applet>*/
import java.applet.*;
import java.awt.*;
public class b extends Applet
{
public void paint(Graphics g)
{
int R=Integer.parseInt(getParameter("radius"));
int x,y=R*2;
g.drawOval(0,0,R*2,R*2);
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(x,0,y,R*2);
g.drawLine(0,y,R*2,x);
y-=R/45;
}
for(x=0;x<=R*2;x+=R/45)
{
g.drawLine(0,x,R*2,x);
g.drawLine(x,0,x,R*2);
}
}
}
Comments
Post a Comment