At the first look you might be tempted to throw everything together in one single class that swingg provide the external API, the model handling state and notificationsevent handling, layout, and painting. Notice the explicit use of the Override annotation before the method declaration.
You just insert one class, compiled with Swing components, into another. Painting on a component is enabled by overriding the paintComponent Graphics method in the JComponent class. More than that, this problem goes directly onto my checklist as: This can be handy if you need to subclass a Swing component in place for just a little modification, or if the component can't be instantiated as JavaBean. The Graphics class presents us with various methods to paint different shapes, line strokes and fonts on any component or container, thus enabling us to completely design a component from scratch. During the course of my career as a swing developer I found myself on numerous occasions writing the same code to create and execute a SwingWorker vomponent an ActionEvent.This article, How To Write a Custom Swing Component should be really helpful. It components, the task of creating a custom Swing component. covers replicating a Windows slider control that has both.