Start simpler. If you only use one method, it should work fine.
public class Main extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// draw grass
Color brightGreen= new Color(60,176,31);
...
// draw flower
Color pinkFlower = new Color(225,153,153);
...
}
}
So if you want to extract the two colors and drawings into methods, you only need to copy those exact lines between the comments (you can even use your IDE features to "Extract Method"), not add another super.paintComponent(g)
(which is what is clearing the panel)
Regarding the question title, private void
isn't the issue or related to the solution, really.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…