1

I read source code of Java Graphics abstract class, I am curious how does this abstract void drawline method draws lines in JComponent's paint(Graphics g) and paintComponent(Graphics g). I know that abstract methods have no method body. I couldn't find any relevant examples with Google. If possible, can you provide me a link to source code of this method.

  • Possible duplicate of [How does paintComponent work?](https://stackoverflow.com/questions/15544549/how-does-paintcomponent-work) – Gatusko Aug 22 '18 at 21:16
  • The core API is responsible for creating the platform implementation of the `Graphics` object. How this is done, is obviously down to the native code of the platform, it then links this to the graphical API of the platform, on Windows, this can be DirectX or OpenGL, on MacOS, it's probably the Quartz library and linux it's probably OpenGL (guessing - which is kind of the point). The point is, this can change (and can change for the same platform) and your code shouldn't care – MadProgrammer Aug 22 '18 at 21:56
  • [The 2D Graphics Group](http://openjdk.java.net/groups/2d/) of the OpenJDK project might be a good place to start – MadProgrammer Aug 22 '18 at 21:58

1 Answers1

1

Mad Programmer is right, all of java's graphics and graphics2d methods is directed with native codes. If you're curious about these native codes, open src zip of your JDK go to Java Desktop/sun/java2d/windows/GDIRenderer. You can see some native methods for graphics class.

Joe Vanjik
  • 357
  • 2
  • 7