-3

I have override paintComponents method, but when I am using it and run my program then it does not show any circle and lines. Recently frakcool said it is not paintComponents method, it is paintComponent method. I found out but I didn't get any paintComponent method.

This picture shows that i have not got any paintComponent method:

this picture shows that i have not got any paintComponent method.

Codes are here.

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                SecondActivity frame = new SecondActivity();
                frame.setBackground(Color.WHITE);
                frame.paintComponents(null);
              //  frame.paint(null);
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}

@Override
public void paintComponents(Graphics g) {
    // TODO Auto-generated method stub
    super.paintComponents(g);
    Graphics2D g2d = (Graphics2D) g;

    drawCircle(g2d,centerX,centerY,r);
    drawLineAzim(g2d);
    drawLineEle(g2d);

}
tzrm
  • 513
  • 1
  • 8
  • 14
  • As I said in [this comment](https://stackoverflow.com/questions/48539169/how-to-draw-the-radius-of-a-circle-without-it-being-shorter-or-larger-than-the-c/48548823?noredirect=1#comment84166832_48548823) and showed in my answer to your other question, you need to override `paintComponent()` not `paintComponentS()`. That method belongs to `JPanel` and that's why I extended from it. – Frakcool Feb 02 '18 at 16:00
  • (1-) `recently frakcool said it is not paintComponents method, it is paintComponent method.` - so why are you still implementing the wrong method??? Did you even search the forum for other examples using the `paintComponent(...)` method??? – camickr Feb 02 '18 at 16:00
  • For better help sooner (re)read the [mcve] guide – Frakcool Feb 02 '18 at 16:03
  • But I am unable to get paintComponent method please Help . Where should I look for it.? – Ashu Ansari Feb 03 '18 at 13:48

1 Answers1

0

You are overriding the wrong method. Get rid of the "s" at the end of the method name. You need to override paintComponent(...).

But, you also need to override the paintComponent(...) method of a JPanel, You can't just add the method to your class and expect it to work. This is Java 101.

Start with the working examples found in the Swing tutorial on Custom Painting

camickr
  • 321,443
  • 19
  • 166
  • 288