[ scatter_dig.java ]
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="scatter_dig" width=500 height=400>
</applet>
*/
public class scatter_dig extends Applet
{
int no[],size;
int h,w;
public void init()
{
int i=0;
no=new int[100];
String line;
try
{
File f=new File("E:\\SCATTER\\abc.txt");
BufferedReader br=new BufferedReader(new FileReader(f));
while( (line=br.readLine())!=null)
{
no[i]=Integer.parseInt(line);
i++;
}
size=i;
}
catch(Exception e)
{
}
}
public void paint(Graphics g)
{
h=getHeight();
w=getWidth();
drawPlane(g);
drawScatter(g);
g.setFont(new Font(Font.SERIF,Font.BOLD,27));
g.drawString("SCATTER DIAGRAM",w/2-100,20);
g.setFont(new Font(Font.SERIF,Font.PLAIN,18));
g.drawString("--Pankaj Sharma",w/2,40);
showStatus("pankaj Sharma");
}
public void drawPlane(Graphics g)
{
int linex=50,liney=h-50;
int diff=((h-100)/10);
g.drawLine(50,50,50,h-50);
g.drawLine(50,h-50,w-50,h-50);
for(int i=0;i<=10;i++)
{
g.drawLine(linex-10,liney,linex,liney);
g.drawString(i*10+"",linex-20,liney);
liney=liney-diff;
}
for(int i=0;i<size+5;i++)
{
g.drawLine(linex,h-50,linex,h-40);
g.drawString(i+"",linex-5,h-25);
linex=linex+20;
}
}
public void drawScatter(Graphics g)
{
int pointx=50;
for(int i=0;i<size-1;i++)
{
g.drawLine(pointx,h-50-((h-100)*no[i])/100,pointx+20,h-50-((h-100)*no[i+1])/100);
pointx=pointx+20;
}
}
}
No comments:
Post a Comment