我的代码:
public class YesOrNo{
Graphics g;
public void createAndShowGui() {
JPanel x=new JPanel(){
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
}
}
public void drawARectangle(){
g.drawRect(10, 10, 50, 50);
}
}
我知道我可以在paintComponent中调用一个方法并将g
作为参数传递给它,但你可以在paintComponent
内调用该方法吗?