
Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs. JAVA SWING GUI TUTORIAL. These notes are based on the excellent book, 'Core Java, Vol 1' by Horstmann and Cornell, chapter 7, graphics programming. Created by dovari.sudheerkiran@gmail.com The Java Swing tutorial Introduction First Programs Menus and Toolbars Swing Layout Management Swing Events.
The Car class does not extend any JComponent derived class, and so your code will fail - it won't even compile because you can't add a Car instance to a JFrame. Have it extend JPanel or JComponent at least.
Either that, or if you want to leave it as a logical and non-component class, then combine it with a JPanel class that can draw it by calling Car's paintComponent within the JPanel's own paintComponent override. Don't forget the @Override annotation as well when you think that you're over-riding a method (i.e., paintComponent). – Oct 26 '15 at 0:53.