2012-11-16 37 views
0

画我有我的类中声明:在一个JPanel

public class myRightPanel extends JPanel 

然后我覆盖paintComponent我的超类的这样的:

public void paintComponent(Graphics g){ 
     super.paintComponents(g); 
       //Draw bunch of things here 
} 

现在事实证明我还需要这需要一种方法在两个整数(x,y)参数中添加一些东西到我已经在该坐标处绘制的myRightPanel。当我已经覆盖我的paintComponent()时,我该怎么做?

+0

1)[tag:eclipse],[tag:netbeans]和[tag:jdk]究竟做了什么? 2)为了更快地获得更好的帮助,请发布[SSCCE](http://sscce.org/)。 –

+0

你是否忽略了我对标签的评论? –

回答

0

您需要使用Graphics对象来绘制所需的任何内容。

例如:

public void paintComponent(Graphics g){ 
    super.paintComponents(g); 
    g.drawString("Hello test", 0, 0); 
} 

我建议你阅读的Java 2D教程: http://docs.oracle.com/javase/tutorial/2d/index.html

+0

如果没有任何后代,文本将不可见,如[此处]所示(http://stackoverflow.com/a/2658663/230513);另见[答](http://stackoverflow.com/a/13333956/230513)。 – trashgod

3

Store中的X,Y为Point为类的属性,因此是paint方法中访问。致电repaint()

+0

我打电话重画什么?我怎么称呼它? –

+0

再次,这次更大声一点.. ***为了更好地帮助,请发布[SSCCE](http://sscce.org/)。*** –