Node オブジェクトの ArrayList を表示しようとしているシミュレーターを構築しています。画面の中央への描画を担当する JComponent のオーバーライドされた paintComponent で拡張 for ループを使用しています。
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);
}
}
}
現在、ループ内の印刷は正しく印刷されていますが、楕円形は表示されません。ただし、ループの外側に描画する楕円セットは正常に機能しています。私が間違っているかもしれないことについての洞察は大歓迎です。前もって感謝します。