-1

I'm building a simulator that is trying to display an ArrayList of Node objects and I'm using an enhanced for loop in the overridden paintComponent of my JComponent responsible for drawing to the center of my screen.

package networkSimulation;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;

public class mainComponent extends JComponent{

    public void paintComponent(Graphics g){
        NetworkGUI.updateForWindowSize();
        g.drawLine(-50, (int)NetworkGUI.windowHeight - 130, (int)NetworkGUI.windowWidth + 50, (int)NetworkGUI.windowHeight - 130);
        g.fillOval(100, 100, 100, 100);

        //Draw the contents of the graph
        for(Node node: NetworkGUI.graph.getNodes()){
            System.out.println("Drawing a Node at " + node.getX() + ',' + node.getY());
            g.fillOval((int)node.getX(), (int)node.getY(), 100, 100);
        }

    }

}

Currently the print in my loop is printing correctly, but the oval isn't appearing. However, the oval set to draw outside of the loop is working fine. Any insight as to what I might be doing wrong would be greatly appreciated. Thank you in advance.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
avorum
  • 2,051
  • 10
  • 35
  • 48
  • 3
    I can't see why the code is not working based on your posted code alone. If you don't get a decent answer soon, consider creating and posting an [sscce](http://sscce.org) (please check the link). – Hovercraft Full Of Eels Oct 21 '12 at 19:00
  • 1
    Side note, please call `super.paintComponent`. I'm not sure if this will help, but [this](http://stackoverflow.com/questions/12683533/drawing-a-rectangle-that-wont-disappear-in-next-paint/12683601#12683601) displays a complex output in the `paint` method – MadProgrammer Oct 21 '12 at 19:46
  • 1
    Try to avoid network activity `paintComponent()` – trashgod Oct 21 '12 at 23:07

0 Answers0