[求助]请问paintComponent要怎么用?
JComponet中的paintComponent要怎么用呢?感觉好象和paint差不多,但------:
import java.awt.*;
import javax.swing.*;
class Mycanvas extends JPanel{
public void paintComponet(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
g.drawString("a JPanle used as canvas",50,50);
}
}
public class Apt extends JApplet{
Mycanvas canvas;
JPanel panel;
JButton button;
public void init(){
canvas=new Mycanvas();panel=new JPanel();
button=new JButton("ok");
canvas.setVisible(true);
panel.add(button);Container con=getContentPane();
con.add(panel,BorderLayout.NORTH);
con.add(canvas,BorderLayout.CENTER);
}
}
书上的例子,结果看起来和这个方法并没什么关系...
文档上写的:
Calls the UI delegate's paint method, if the UI delegate is non-null
. We pass the delegate a copy of the Graphics
object to protect.....
似乎也没写清楚用法,反正是没看明白...