From the course: Java Design Patterns: Structural

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Avoid complex constructions

Avoid complex constructions - Java Tutorial

From the course: Java Design Patterns: Structural

Start my 1-month free trial

Avoid complex constructions

- [Instructor] In this example, I've got an app that draws shapes on a graphical user interface. At the moment, there are a lot of classes and the hierarchy is quite complicated. The app has a class called canvas which has a main method. If you're not familiar with swing, don't worry too much about how the code and the main method works. You just need to know that what it does is create a canvas that shapes can be drawn on. Then underneath the main method, there's a paints method where we specify the shapes we want to draw. In this method, I'm creating a blue square object and drawing it on the canvas. Then I'm doing the same with a red circle and then a green triangle. This paint method gets called automatically by swing, because my canvas class extends the J panel class from swing. If I run the app, it opens up a canvas and draws those three shapes on it. This is quite a simple output for an app that has so many…

Contents