0

In my main class i have built a JFrame and added functionality to a button which gets stock values from yahoos sites. Im currently storing the stock values in an arraylist and passing it to the other class, but thats not the problem. My problem is i dont know how to call the "paintComponent" method from my frame, because of the "Graphics g" variable. I think im missing the big picture here, am i on the right tracks or should i be looking to solve this problem some other way?

here is my graph class:

public class graph  {
    private static Main main;

public void paintComponent(Graphics g) {

Graphics2D graph2 = (Graphics2D)g;
graph2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ArrayList<String> first = main.getFirst();
int x1 = 0;
int x2= 1;
for (String x : first)  {

    String[] parts = x.split(",");
    int y1 = Integer.parseInt(parts[0]); 
    int y2= Integer.parseInt(parts[1]);


    Shape drawLine = new Line2D.Float(y1, x1, y2, x2);
    graph2.draw(drawLine);
}
}
}
Anton
  • 581
  • 1
  • 5
  • 23

1 Answers1

0

You are not supposed to call this method by yourself. graph (which should be called Graph) has to extend a Swing component so that you just have to add it as a child of one of your containers to display it.

Dici
  • 25,226
  • 7
  • 41
  • 82
  • Thanks for the reply, but how can i decide which panel i add it to? and what do you mean by "adding it as a child"? – Anton Apr 19 '15 at 22:02
  • Don't understand your first question, for the secon, just consider this code : `Container container = new Container(); container.add(myComponent);` – Dici Apr 19 '15 at 22:06
  • myComponent being what in this case? – Anton Apr 19 '15 at 22:16
  • a `graph` instance, if you made `graph` extend a Swing component – Dici Apr 20 '15 at 07:08