Java graphics are, unfortunately, complicated, and like most of Java, there is more than one way of doing something. In this course we will be learning to use SWING for making GUIs and drawing graphics.
This is the "newer"
graphics package. It does all of the drawing itself, so your application will
look the same on every operating system. It may be a bit slower because of
this though.
Swing is built on top of AWT and still uses a lot of AWT stuff – e.g. the AWT Color
class. It hasn't replaced everything, mostly just the buttons, labels, etc.
that you place on the screen. All of the Swing objects start with a J. For
example "Button" is an AWT object, but "JButton" is Swing.
Swing normally looks better than AWT, but some of it is stupidly complex. Don't ever put AWT objects onto a Swing one if there is a Swing object that does the same thing. Why not? Strange things happen and your program may not work properly. For example, adding Label to a JPanel is bad because you should use JLabel. Two of the most common mistakes (based on comments on the internet are):
Pie Chart in SWING | Pie Chart in JavaFX |
---|---|
Swing Source code | JavaFX Source Code |
Types of objects: Containers vs Components
Containers can be inside other containers: e.g. two JPanels inside another JPanel inside a JFrame
Hierarchy of AWT classes (partial)
Hierarchy of Swing classes (partial)
Hierarchy of Swing classes (not up to date)