|
Newbie
Join Date: Jul 2005
Posts: 15
Rep Power: 0 
|
Graphic Problem
I am trying to display a line graph from a given arrays of integers, which are stores as x and y points consecutively. (ie. int values[] = {x0,y0,x1,y1,etc...})
However, after I compiled and run the code, no graph is displayed. What's wrong?...
import java.awt.*;
import javax.swing.*;
public class GraphicTest extends JPanel
{
private int values[]={2,5,6,34,12,28,18,24,22,26,25,16,30,41,34,7,39,18};
public void paintGraph(Graphics aGraphics, int values[])
{
int x = values[0];
int y = values[1];
aGraphics.drawRect(x-2,y-2,x+2,y+2);
for (int i=0; i<values.length; i+=2)
{
aGraphics.drawLine(x,y,values[i],values[i+1]);
x = values[i];
y = values[i+1];
aGraphics.drawRect(x-2,y-2,x+2,y+2);
}
}
public static void main (String args[])
{
JFrame frame = new JFrame();
frame.setLocation(100,100);
frame.setSize(400,300);
frame.getContentPane().add(new GraphicTest());
frame.show();
}
}
|