I want a java sourse code for systech transpotation service
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package optimalcluster;
/**
*
* @author CSEEXAM2008
*/
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class GraphingData extends JPanel {
double[] data = {
0.504782921308152, 1.174144134378306, 2.0933754535558546,6.2625807939548823,8.8484441414277364,10.0000003,12.908978000,14.8906789456,12.9087654567 };
final int PAD = 20;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
// Draw ordinate.
g2.draw(new Line2D.Double(PAD, PAD, PAD, h-PAD));
// Draw abcissa.
g2.draw(new Line2D.Double(PAD, h-PAD, w-PAD, h-PAD));
double xInc = (double)(w - 2*PAD)/(data.length-1);
double scale = (double)(h - 2*PAD)/getMax();
// Mark data points.
g2.setPaint(Color.red);
for(int i = 0; i < data.length; i++) {
double x = PAD + i*xInc;
double y = h - PAD - scale*data[i];
g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
}
g2.setPaint(Color.black);
for(int i = 0; i < data.length; i++) {
double x = PAD + i*xInc;
double y = h - PAD - scale*data[i];
g2.fill(new Ellipse2D.Double(x-2+4, y-2+4, 4, 4));
}
g2.setPaint(Color.blue);
for(int i = 0; i < data.length; i++) {
double x = PAD + i*xInc;
double y = h - PAD - scale*data[i];
g2.fill(new Ellipse2D.Double(x-2+6, y-2+6, 4, 4));
}
g2.setPaint(Color.pink);
for(int i = 0; i < data.length; i++) {
double x = PAD + i*xInc;
double y = h - PAD - scale*data[i];
g2.fill(new Ellipse2D.Double(x-2+8, y-2+8, 4, 4));
}
}
private double getMax() {
double max = -Integer.MAX_VALUE;
for(int i = 0; i < data.length; i++) {
if(data[i] > max)
max = data[i];
}
return max;
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new GraphingData());
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
519 views
Usually answered in minutes!
×