0

我有带有一些组件的 JFrame 和 JPanel,其中将是图形对象。我正在尝试在 JPanel 上添加 Line

DrawingPanel()
{
    DrawCellsComponent drawCellsComponent = new DrawCellsComponent();
    add(drawCellsComponent);
}

这是组件的代码。

public void paintConponent(Graphics g)
{
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(Color.RED);
    g2.draw(new Line2D.Double(0, 0, 250, 250));
}

JPanel 上没有任何线路。有什么问题?

4

1 回答 1

0

Problem solved. Just draw in JPanel not in JComponent

于 2012-06-20T17:42:28.067 回答