if i have a file DrawLines with
public class DrawLine extends JComponent {
...
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Graphics2D graphics2d = (Graphics2D) graphics;
graphics2d.setStroke(new BasicStroke(this.width));
graphics2d.draw(new Line2D.Float(this.x1, this.y1, this.x2, this.y2));
}
}
why doesnt this draw a line when i use it in my main JPanel class?
public class LevelBuilder extends JFrame {
public LevelBuilder() {
super("Level Builder");
...
for (int horLine = 0; horLine < CELLS_IN_COL; horLine++) {
getContentPane().add(new DrawLine(...));
}
for (int verLine = 0; verLine < CELLS_IN_ROW; verLine++) {
getContentPane().add(new DrawLine(...));
}
}
}