import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.*;
public class pro extends JFrame{
double maxc,minc;
int s1,s2,t;
double c[]=new double[500];
double adjc[]=new double[500];
public static void main(String[] args){
pro test = new pro();
test.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}
});
test.setBounds( 0, 0, 700, 700);
test.setVisible(true);
}
pro(){
try{
BufferedReader br =new BufferedReader(new FileReader("data.txt"));
String str;
String x[]=new String[3];
for(int i=0; i<90; i++){
str = br.readLine();
x=str.split(",");
t=Integer.valueOf(x[0]);
c[t]=Double.valueOf(x[1]);
}
br.close();
}
catch(IOException e){System.out.println("入出力エラーです。");}
}
public void paint(Graphics g){
double x,y,z;
int px,py;
int px1,px2,py1,py2;
Graphics2D g2 = (Graphics2D)g;
BufferedImage readImage = null;
if (readImage == null){
readImage = new BufferedImage(getWidth(), getHeight(),
BufferedImage.TYPE_INT_BGR);
}
Graphics2D off = readImage.createGraphics();
off.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
BasicStroke wideStroke = new BasicStroke(2.0f);
off.setStroke(wideStroke);
off.setPaint(Color.white);
off.fillRect(0,0,700,700);
int c1,c2;
minc=999;
maxc=-999;
for (t=1;t<90;t++){
if (c[t]>maxc)maxc=c[t];
if (c[t]<minc)minc=c[t];
}
for (t=1;t<90;t++){
adjc[t]=(c[t]-minc)/(maxc-minc);
}
off.setColor(Color.yellow);
off.fillRect(0,0,800,800);
off.setColor(Color.red);
off.drawLine(100,600,600,600);
off.drawLine(100,600,100,100);
for (t=1;t<89;t++){
c1=(int)(500*adjc[t]);
c2=(int)(500*adjc[t+1]);
off.drawLine(100+5*t,600-c1,100+5*t+5,600-c2);
}
if (readImage != null){g2.drawImage(readImage,0,0, this);}
try {
boolean result =
ImageIO.write(readImage, "jpg", new File("sam.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
最終更新:2010年12月07日 20:39