In this part of my Java Video Tutorial, I continue to show you how to make a Java paint application. If you missed part 1 watch it.
I cover numerous topics including: how to draw lines, ellipses, brush strokes. I also cover how to save transparency values for shapes. And, because you requested it how to create a custom event listener and much more.
All of the code follows the video and it is heavily commented. After this tutorial, you’ll be able to make an app with much of the functionality of Photoshop.
If you like videos like this, please tell Google [googleplusone]
Sharing is always nice [nttfblike]
Code from the Video
hello admin nice tutorial thnxs for this…..
pls tell me that how can I add “Undo” and “Redo” functionality in my paint application?
You’re very welcome 🙂 You could delete the last shape added to the array list. You could create another array list that holds boolean values that toggle the shape on and off. There are a couple ways to do that. I hope that helps
hi , this is really helpful video series for the people who wanna learn java ….. I learn lots in very short period of time ….. many thanks. could you please explain how can we implement save ( all the drawings as project file ) then later we can load again and do some modification
(example photoshop psd file)
thank you
Thank you 🙂 I’m glad you enjoyed them. It is actually pretty easy to do that. This tutorial explains how to work with files with java . Once you can do that, just save the arraylist data to a file. Then load the array list from a file. Then you can save everything you draw.
many thx for the quick reply…….. could you please explain how can we implement the feature for edit the shape once we draw ….
( example change the color …. change the size ….. )
thank you
You could create a system in which you can cycle back through each shape in the array list with the arrow keys or something like that. I don’t know of anyway you could select them with a mouse click. Then as you cycle through the shapes you could highlight them in some way and then apply stroke / fill changes. That is my quickest solution
Hi Derek. Not sure if it is best to ask a question on Youtube or on your website. My questions is: Box theBox = Box.createHorizontalBox(); Does this statement give theBox access to all Box classes and methods or does it just set theBox equal to a value created from the createHorizontalBox method? Also I noticed that there is not a call for the paint() method. Is this done with repaint(). If so, how? Thanks again for your help and videos.
Hey Derek thanks for the awesome tutorials. Erm the code at line 294 isn’t needed right?
Thank you 🙂 I’m not sure which line you are referring to. Line 294 in the code I provide on this page is needed, but I want to make sure we are referring to the same thing. Sorry if that was confusing.
Hello,
i have a question:
I have added a slider that changes from 1 to 20 with a default size of 1.This slider is for changing the strokeSize dynamically,so i have created a variable strokeSizeVal and the slider + Listener for it and the new stroke size updates and works just fine,but it updates for all the shapes that are added in the array..Even for shapes that are already drawn.
I have put graphSettings.setStroke(new BasicStroke(strokeSizeVal); just under the comment: // Defines the line width of the stroke
in public void paint(Graphics g) { … }
How can i change this,so that it doesn’t update all the shapes in the array and is valid only for newly created shapes?
Thanks!
I’d save individual stroke weights in a multidimensional array along with the objects. I hope that helps 🙂
Your tutorials are the best..i am a beginner in java and i wanna ask a couple of questions.
What if I dont have icons on my buttons?
What code should I add if i want pensize and upload an image to draw on?
Thanks,
Ron
Hi Ron,
Thank you 🙂 I’m glad you like them. What exactly are you trying to do. I’ll do my best to help.