PaintComponent (g) or paintComponent (g2)?

public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.fillRect(0,0,25,25);
}

OR

public void paintComponent(Graphics g){
    Graphics2D g2 = (Graphics2D) g;
    super.paintComponent(g2);
    g2.fillRect(0,0,25,25);
}

What would be correct if I used Graphics2D? Will I draw component (g) or pass it instead of g2?

Sorry if this is a stupid question, I would use the second one, but I just want to know what will be the right way if I do something wrong.

+4
source share
2 answers

Graphics . , Graphics Java-, Graphics2D DebugGraphics, , g Graphics2D, ( ). DebugGraphics .

, , 100%.

+4

paintComponent Graphics , Graphics2D - Graphics. , g super.paintComponent g2. , super.paintComponent , Graphics, Graphics2D ( ).

+4

Source: https://habr.com/ru/post/1651622/


All Articles