In this part of my Java Video Tutorial, I cover how to draw 2D graphics in Java. This tutorial will serve as an introduction before I make a paint application with Java.
I cover drawing lines, curves, ellipses, rectangles and numerous other shapes. Then we look at strokes, fills and gradients.
All of the code follows the video and can serve as a cheat sheet, or an additional teaching tool.
If you like videos like this, please tell Google [googleplusone]
Sharing is always appreciated [nttfblike]
Code from the Video
This is really a great tut from you!
Thank you 🙂
Hi Derek,
Thanks a lot again for your great tutorials.
I have two questions :
1. How can I draw an arrow instead of a line ? I have graphical objects and I want to show their relations by drawing a directed arrow connecting them.
2. In your tutorial we add the drawing by initializing an object from DrawStuff class , and in the paint method you create the Shape objects and draw them.
Suppose I have a list of Shape objects , how can I send it to this method to draw them?
Thanks in advance for your help.
Your very welcome 🙂 You could store polygons like a line and then draw them on the screen. I get into manipulating polygons as the tutorial continues.
Sorry I did not get you fully
So is there a way to draw an arrow instead of a line by giving starting and ending coordinates ? Do we have an arrow as a Shape object like a Line2D?
You’ll have to create a polygon in the shape of an arrow. Then you can draw that polygon like any other.