Java Fractal Explorer [3/8]
Git video snapshots:
https://github.com/william-fiset/FractalExplorer/commits/master
===============================================================================
Developer tools I used in the creation/testing of the content in these videos:
1) Sublime text, my favorite lightweight code editor (https://www.sublimetext.com).
NOTE: I'm often asked about the color scheme I use, find it here: https://github.com/williamfiset/dotfiles/tree/master/sublime
2) Kite, a free AI-powered coding assistant that provides smart code completions while typing:
https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=williamfiset&utm_content=description-only
===============================================================================
What You'll Learn
This video demonstrates how to create a custom Canvas class in Java, extending the JPanel class, and override its getPreferredSize and paintComponent methods to display a fractal image on the screen. The video uses Sublime text as the code editor and utilizes Java's built-in classes such as BufferedImage and Graphics.
Full Transcript
in this video we are going to look at how to put a canvas on top fire jframe the reason we want canvas is because we want to actually be able to manipulate the pixels and change their colors and some have something dynamic that's responsive and not just a frame which we actually can't change the color of the pixels for so we are going to need two things we're going to need canvas oops campus and we're also going to need something to draw on our campus and that's going to be a buffered image which I'm era called a fractal image canvas unfortunately is not a built in class in Java so we are going to have to create it ourselves so let's do that just down here and we're going to make it a private inner class because we want it to be able to access some of our methods and the fractal Explorer and our canvas is going to extended the jpanel because we want with a jpanel on top of the jframe which is our fractal explorer program our canvas is going to override two methods get preferred size and paint component which is going to tell our canvas how to behave so to make sure we're overriding put the app override sign this is optional public I mention it bird oh sighs and get preferred size should return fruit size or canvas which we already know what this is because we know what the dimension of the jframe is it's going to be the same let's just going to deal with and height the next method we're going to override is a more important paint component and it takes a graphics object as an argument and this graphics object is going to be the object that's going to draw our fractal image onto the canvas itself so i'm going to call this the drawing object and the drawing object is just going to call one method called draw image and this is going to be the method which is going to be responsible for drawing that fractal image on the screen we're going to make the fractal image be 600 x 600 or width x height so we're just going to place it at the top left corner of the screen so these are XY coordinates and the last argument is for an observer we don't have an observer so put null right there so the last thing we need to do is actually initialize the canvas and the frankie lymon and display them on the screen to do that let's add another method called add canvas so private void add canvas and we're just going to initialize the canvas say new canvas and lets it should initialize the fractal image so create new bufferedimage and this cases arguments the size and the type of bufferedimage we want a bufferedimage types are constants in the bufferedimage class so so we can specify the type of one and we just want type called type and oops RGB which is the standard type for a red green blue so next we are going to set the canvases property to be visible and lastly we are going to add them to the frame so canvas and we're going to put this in the center so I borderlayout dot center oh I can see I have a spelling mistake right here and get preferred size so this is would throw an error because at override would say hey this isn't actually a method we're overriding because it's not spelled correctly so let's fix that it and now let's actually run this program and see if we have successfully added the canvas to the screen let's go to the terminal and do pilus and run it and as we can see instead of having a frame with a white background now have a frame with a black background and the black simply means that we have successfully added the canvas on top of the frame so guys thank you for watching and I'll see you in the next video
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from WilliamFiset · WilliamFiset · 21 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
▶
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
JES Image Manipulation - 2 - Installation
WilliamFiset
JES Image Manipulation - 3 - User Interface
WilliamFiset
JES Image Manipulation - 5 - Negative
WilliamFiset
JES Image Manipulation - 6 - Black & White
WilliamFiset
JES Image Manipulation - 4 - Grayscale
WilliamFiset
JES Image Manipulation - 8 - Blur
WilliamFiset
JES Image Manipulation - 7 - Edge Detection
WilliamFiset
JES Image Manipulation - 9 - Blend
WilliamFiset
JES Image Manipulation - 10 - Matte
WilliamFiset
JES Image Manipulation - 13 - Rotate90
WilliamFiset
JES Image Manipulation - 12 - Mirroring Picture
WilliamFiset
JES Image Manipulation - 11 - Crop Image
WilliamFiset
JES Image Manipulation - 14 - Stretch picture
WilliamFiset
Java Fractal Explorer [6/8]
WilliamFiset
Java Fractal Explorer [4/8]
WilliamFiset
Java Fractal Explorer [8/8]
WilliamFiset
Java Fractal Explorer [5/8]
WilliamFiset
Java Fractal Explorer [2/8]
WilliamFiset
Java Fractal Explorer [7/8]
WilliamFiset
Java Fractal Explorer [1/8]
WilliamFiset
Java Fractal Explorer [3/8]
WilliamFiset
Introduction [Programming Competition Problems]
WilliamFiset
String Manipulation 1 [Programming Competition Problems]
WilliamFiset
String Manipulation 2 [Programming Competition Problems]
WilliamFiset
Graph Theory 1 [Programming Competition Problems]
WilliamFiset
Logic 1 [Programming Competition Problems]
WilliamFiset
Grid Problems 1 [Programming Competition Problems]
WilliamFiset
Dynamic Programming 1 [Programming Competition Problems]
WilliamFiset
Introduction to Big-O
WilliamFiset
Dynamic and Static Arrays
WilliamFiset
Dynamic Array Code
WilliamFiset
Linked Lists Introduction
WilliamFiset
Doubly Linked List Code
WilliamFiset
Stack Introduction
WilliamFiset
Stack Implementation
WilliamFiset
Stack Code
WilliamFiset
Queue Introduction
WilliamFiset
Queue Implementation
WilliamFiset
Queue Code
WilliamFiset
Priority Queue Introduction
WilliamFiset
Priority Queue Min Heaps and Max Heaps
WilliamFiset
Priority Queue Inserting Elements
WilliamFiset
Priority Queue Removing Elements
WilliamFiset
Priority Queue Code
WilliamFiset
Union Find Introduction
WilliamFiset
Union Find Kruskal's Algorithm
WilliamFiset
Union Find - Union and Find Operations
WilliamFiset
Union Find Path Compression
WilliamFiset
Union Find Code
WilliamFiset
Binary Search Tree Introduction
WilliamFiset
Binary Search Tree Insertion
WilliamFiset
Binary Search Tree Removal
WilliamFiset
Binary Search Tree Traversals
WilliamFiset
Binary Search Tree Code
WilliamFiset
Fenwick Tree range queries
WilliamFiset
Fenwick Tree point updates
WilliamFiset
Fenwick Tree construction
WilliamFiset
Fenwick tree source code
WilliamFiset
Hash table hash function
WilliamFiset
Hash table separate chaining
WilliamFiset
Related AI Lessons
⚡
⚡
⚡
⚡
Bloom Filters, Explained Properly
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Medium · Python
🎓
Tutor Explanation
DeepCamp AI