Here's the code for the picture in the thumbnail. I didn't have time to code this with you guys since I'm trying to cut down on the length of my videos: // Landscape Image //--------------------------------------------------------- public class Main{ public static void main(String[] args) {
new MyFrame();
} } //--------------------------------------------------------- import java.awt.*; import javax.swing.*; public class MyFrame extends JFrame{
MyPanel panel;
MyFrame(){
panel = new MyPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(panel); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); } } //--------------------------------------------------------- import java.awt.*; import javax.swing.*; public class MyPanel extends JPanel{ Image image;
MyPanel(){
image = new ImageIcon("sky.png").getImage(); this.setPreferredSize(new Dimension(500,500));
After I saw the red background that I set I got very happy, at least I saw that something is working maybe now I can focus on programming and quit gaming because the past semester I am just copying my classmates work and not attending classes but when I see and try this tutorial then it worked, It got me very excited and motivated to continue, thank you very much brother keep up.... -to someone who can relate in this comment like it I'm just curious if someone experienced it beside me.
Sometimes if you run the code, it might maintain the previous state of the canvas. What you need to do is run each file individually, before running the main file. It might not apply to everyone, but it did for me (I am on Sublime Text 3).
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
previously i watch your pong project and i don't understand method paint is work with out call so i back to your this new video and i found your description thank for your hard work.
Thank You for this video! You have just shown me a bit from the fun side of Java. And by the way, it can be useful while making business charts for the accounting for example.
For some reason when I try to draw the image it doesn't work, I have tried multiple images and even copying the exact code from the description but nothing seems to work.
Hi First, thank you so much, your tutorials help me sooo much to learn about this stuff as someone that randomly jumped in! and i have a question, could you go more into strokes, because there is more about them as shown in your video, maybe you could mix this into a next tutorial for graphics2d or something else but the potential for strokes is a bit lost there, but its also not that big but its something that would have also fit in pretty good
Hi! I have a problem: My code is the same but I can't see the line (like at 4:00). The line became visible only if I call the repaint() method in the paint() method after the drawLine() call. Can you explain this problem, please? *** EDIT: I see that the issue could be fixed by calling the super.paint(g) method at the beginnin of our overriding method. *** After that, I would be grateful if you did a video to explain something about BufferedImage, BufferStrategy, VolatileImage end/or similar. And it would be very interesting and useful if sometimes you explained some efficiency information just to understand which class is more suitable for our use. Thank you!
I love your videos but i have a question is there a way to draw on a panel without creating a new class and extending it to JPanel if there is a way help pls
This is how I fixed it, created a method to return the instance of panel in the MyFrame class: MyPanel getpanel(){ return panel; } On the MyPanel class, I created a new method to pass into the data I want to use to draw onto my panel: protected void drawelevators(myarray[] _myarray) { myarray= _myarray; repaint(); } By calling the repaint function, this function is called for painting on the panel: protected void paintComponent(Graphics g) {} on the main thread, I created instances to the the panel object like this: MyFrame frame = new MyFrame(); MyPanel panel = frame.getpanel(); Then I called the function I talked about above: panel.drawelevators(myarray);
Ehhhh so I did this and the ImageIcon doesn't seem to be able to import my images. However, there is another way I learned using the BufferedImage thingy and then surrounding it with try and catch in the constructor. The image works fine with that method but not for the imageicon method like you use, am I missing something? Thank you for all your teachings by the way :'>
Here's my Pokeball 😂: g2D.setPaint(Color.red); g2D.drawArc(200, 0, 100, 100, 0, 180); //draw a half circle g2D.fillArc(200, 0, 100, 100, 0, 180); g2D.setPaint(Color.white); g2D.drawArc(200, 0, 100, 100, 180, 180); //draw a half circle g2D.fillArc(200, 0, 100, 100, 180, 180); g2D.fillOval(230, 30, 40, 40); //fill a small circle inside the big circle g2D.setPaint(Color.black); g2D.drawOval(200, 0, 100, 100); //draw an outline: outside circle g2D.drawOval(230, 30, 40, 40); //draw an outline: middle circle g2D.drawOval(240, 40, 20, 20); //draw an outline: inside circle g2D.drawLine(200, 50, 230, 50); //draw a line inside the ball g2D.drawLine(270, 50, 300, 50); //draw a line inside the ball
I have essentially the same code as in the video for printing an image onto a window, but when I print a 320x240 image onto a 320x240 panel, it lowers the resolution of the image significantly. I can't figure out why it's lowering the quality of the image so much. Is there some in between step that the printing takes that does this, and if so can I avoid it?
Hi Bro, Loving these vids. I have a quick question.. How do I set up eclipse to show the arguments like yours. yours: g2d.drawArc(x, y, width, height, startAngle, arcAngle); mine: g2d.drawArc(arg0, arg1, arg2, arg3, arg4, arg5); If anyone knows what setting I need to enable so the argument tips look like this. Thanks in advance :)
Hello guys, can someone explain to me, why i don't get the proposals shown at 3:18 ? I only get proposals like equals(), getClass(), hashCode(), wait(), etc. but nothing like drawLine, setPaint, etc. :(
Does this support multithreading, python didn’t so that’s why I’m asking before I start my project lol otherwise I’ll have to scrap the graphics which would really suck
Hi to all. I'm having a problem launching this. I copied it almost exactly as coded, with different class names and different shapes. I keep running the package all three files are in as a Java application and it's not showing a window. No errors but that's about it. EDIT: Never mind, I fixed it. My version of Main was opening panels rather than the frames. Thanks for the video, you're really saving my bacon on my undergrad thesis.
I have no idea why I cannot cast "Graphics g" as a Graphics2D. :( It says: "Graphics2D cannot be resolved to a type" and this Exception shows up when I run the program: Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: Graphics2D cannot be resolved to a type
Did you import Graphics2D at the top of your main class's file? That'd be the import java.awt.Graphics2D line at the top of the java file shown in the video. Make sure your imports are correct and that you've imported both Graphics and Graphics2D and then cast Graphics g as Graphics2D in your program.
for code readability. If you want to, there is no problem with that. Once you refer this after 5-10 years, it would be hard to read all of that code, or it could be difficult to read for a colleague.
// ---------------------------------------------
public class Main{
public static void main(String[] args) {
new MyFrame();
}
}
// ----------------------------------------------
import javax.swing.*;
public class MyFrame extends JFrame{
MyPanel panel;
MyFrame(){
panel = new MyPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(panel);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
// ----------------------------------------------
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel{
//Image image;
MyPanel(){
//image = new ImageIcon("sky.png").getImage();
this.setPreferredSize(new Dimension(500,500));
}
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
//g2D.drawImage(image, 0, 0, null);
g2D.setPaint(Color.blue);
g2D.setStroke(new BasicStroke(5));
g2D.drawLine(0, 0, 500, 500);
//g2D.setPaint(Color.pink);
//g2D.drawRect(0, 0, 100, 200);
//g2D.fillRect(0, 0, 100, 200);
//g2D.setPaint(Color.orange);
//g2D.drawOval(0, 0, 100, 100);
//g2D.fillOval(0, 0, 100, 100);
//g2D.setPaint(Color.red);
//g2D.drawArc(0, 0, 100, 100, 0, 180);
//g2D.fillArc(0, 0, 100, 100, 0, 180);
//g2D.setPaint(Color.white);
//g2D.fillArc(0, 0, 100, 100, 180, 180);
//int[] xPoints = {150,250,350};
//int[] yPoints = {300,150,300};
//g2D.setPaint(Color.yellow);
//g2D.drawPolygon(xPoints, yPoints, 3);
//g2D.fillPolygon(xPoints, yPoints, 3);
//g2D.setPaint(Color.magenta);
//g2D.setFont(new Font("Ink Free",Font.BOLD,50));
//g2D.drawString("U R A WINNER! :D", 50, 50);
}
}
hi
Code for Pokemon
g2d.setColor(Color.red);
g2d.fillArc(0, 0, 200, 200, 0, 180);
g2d.setColor(Color.white);
g2d.fillArc(0, 0, 200, 200, 180, 180);
g2d.setColor(Color.black);
g2d.fillOval(80, 80, 50, 50);
g2d.setFont(new Font("MV Boli",Font.BOLD,20));
g2d.drawString("POKEMON", 50, 70);
Practicing...
public class Main{
public static void main(String[]args){
new MyFrame();
}
**************************
import javax.swing.*;
public class MyFrame extends JFrame{
MyPanel panel;
MyFrame(){
panel = new MyPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(panel);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
*****************
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel{
Image image;
MyPanel(){
image = new ImageIcon("landscape.png").getImage();
this.setPreferredSize(new Dimension(100,100));
}
public void paint(Graphics g){
Graphics2D g2D = (Graphics2D) g;
g2D.setPaint(Color.green);
//g2D.setStroke(new BasicStroke(5));
//g2D.drawLine(0,0,250, 250);
//g2D.setPaint(Color.yellow);
//g2D.drawRect(0,0,100,200);
//g2D.fillRect(0,0,100,200);
//g2D.setPaint(Color.orange);
//g2D.drawOval(0,0,100,100);
//g2D.fillOval(0,0,100,100);
g2D.setPaint(Color.red);
//g2D.drawArc(0,0,100,100,0,100);
//g2D.fillArc(0,0,100,100,0,100);
//g2D.setPaint(Color.white);
//g2D.fillArc(0,0,100,100,100,100);
//int[]xPoints = {125,225,325};
//int[]yPoints = {250,300,250};
//g2D.setPaint(Color.green);
//g2D.drawPolygon(xPoints,yPoints,3);
//g2D.fillPolygon(xPoints,yPoints,3);
//g2D.setPaint(Color.gray);
//g2D.setFont(new Font("Times New Roman", Font.PLAIN,18));
//g2D.drawString("GLAMOROUS CODER",100,100);
g2D.drawImage(image,0,0,null);
}
}
Here's the code for the picture in the thumbnail. I didn't have time to code this with you guys since I'm trying to cut down on the length of my videos:
// Landscape Image
//---------------------------------------------------------
public class Main{
public static void main(String[] args) {
new MyFrame();
}
}
//---------------------------------------------------------
import java.awt.*;
import javax.swing.*;
public class MyFrame extends JFrame{
MyPanel panel;
MyFrame(){
panel = new MyPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(panel);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
//---------------------------------------------------------
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel{
Image image;
MyPanel(){
image = new ImageIcon("sky.png").getImage();
this.setPreferredSize(new Dimension(500,500));
}
public void paint(Graphics g){
Graphics2D g2D = (Graphics2D) g;
g2D.drawImage(image, 0, 0, null);
g2D.setPaint(Color.green);
g2D.fillRect(0, 300, 500, 500);
g2D.setPaint(Color.gray);
g2D.fillRect(225, 325, 50, 100);
g2D.fillRect(325, 350, 50, 100);
g2D.fillRect(125, 350, 50, 100);
g2D.setStroke(new BasicStroke(1));
g2D.setPaint(Color.orange);
g2D.fillArc(150, 200, 200, 200, 0, 180);
int[] xPoints = {0,100,200};
int[] yPoints = {300,150,300};
g2D.setPaint(new Color(0x694d00));
g2D.drawPolygon(xPoints, yPoints, xPoints.length);
g2D.fillPolygon(xPoints, yPoints, xPoints.length);
int[] xPoints2 = {300,400,500};
int[] yPoints2 = {300,150,300};
g2D.setPaint(new Color(0x694d00));
g2D.drawPolygon(xPoints2, yPoints2, xPoints.length);
g2D.fillPolygon(xPoints2, yPoints2, xPoints.length);
g2D.setPaint(Color.green);
g2D.setStroke(new BasicStroke(10));
g2D.drawLine(0, 300, 500, 300);
g2D.setPaint(Color.YELLOW);
g2D.setFont(new Font("Ink Free",Font.BOLD,50));
g2D.drawString("Welcome to my city", 25, 75);
}
}
//---------------------------------------------------------
Out of all coding related channels on youtube, this is BY FAR the best one.
This is a brilliant tutorial! straight to the point (well, ignoring the like & subscribe stuff), very straightforward and easy to understand!
Thanks for the useful content
After I saw the red background that I set I got very happy, at least I saw that something is working maybe now I can focus on programming and quit gaming because the past semester I am just copying my classmates work and not attending classes but when I see and try this tutorial then it worked, It got me very excited and motivated to continue, thank you very much brother keep up....
-to someone who can relate in this comment like it I'm just curious if someone experienced it beside me.
Thank you for these tutorials! I have completed a basic java course but it didn't include panels, frames or graphics. Your tutorials are very helpful.
draw rect like get rekt , perfectly explained 🙌 👌
That was great. the first clear description of how to use 2D graphics i've seen.
Want to create moving object from one point to other,and thank you for your teaching in a simple and detailed way of explanation
Great video, easy to follow and understand. Thanks for uploading!
Sometimes if you run the code, it might maintain the previous state of the canvas. What you need to do is run each file individually, before running the main file. It might not apply to everyone, but it did for me (I am on Sublime Text 3).
RUclips never recommend your videos.. I watch a lot of videos related to programming.. i randomly searched bro code.. and found your channel
nice!
thank you for this video . helped me so much to understand GUI
As always .. bery good content
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
thanks you make learning fun and productive😄
This was a good summary on 2D graphics basics. I got this link as a course material.
Great and simple, with no fluff! Thanks much.
Awesome content
I'm glad I find your channel! I've learned and still learning so much things in a short time! ^^
Super helpful
cool video bro.
Nice video !!!!!
Another great one
Great thanks
Very nice video ! 😀😀
You're awesome. I am learning so much from you. Please keep it up.
Your explanation is brilliant!
Thank you so much for the video. Very helpful for a beginner.
Great explained!
Bro is a Java king
Thank you for these tutorials!
Thank you for this understandable tutorial, you're amazing.
previously i watch your pong project and i don't understand method paint is work with out call so i back to your this new video and i found your description thank for your hard work.
thanks for watching! That's one of the reasons I went back to update some of these GUI videos. I feel like I could have explained a few things better
Helpful
Hey , just want to say that your videos are awesome
and this video really helped me , thank you
Really Cool
Gave it a like! Thanks man and great video!
Great video! Thanks alot
i think this is the best playlist available for learning java graphics . Thanks a lot bro. playlist is not updated?
Thanks for the video!
amazing
Thank You for this video! You have just shown me a bit from the fun side of Java. And by the way, it can be useful while making business charts for the accounting for example.
Like it!
For some reason when I try to draw the image it doesn't work, I have tried multiple images and even copying the exact code from the description but nothing seems to work.
thank you for this video, it was very helpful :)
Thanks dude, might create a personal video to help me re-learn this
I love at the begin of this vid that show an image from the game Dragon's Lair
thanks bro
sir, next please🙏 cloth simulation
Good
Thanks so much for helping me cause I didn't have any knowledge about how to set up an image background.
I made two triangles with 5 points :)
int[] triangleXPoints = new int[] {
0, 200, 400, 600, 800
};
int[] triangleYPoints = new int[] {
300, 80, 300, 80, 300
};
g2D.setPaint(Color.yellow);
g2D.fillPolygon(triangleXPoints, triangleYPoints, 5);
I'm first to comment after you 👑
Here you go:
🥇
cool
Muito bom. Obrigado.
Thanks
Hi
First, thank you so much, your tutorials help me sooo much to learn about this stuff as someone that randomly jumped in!
and i have a question, could you go more into strokes, because there is more about them as shown in your video, maybe you could mix this into a next tutorial for graphics2d or something else but the potential for strokes is a bit lost there, but its also not that big but its something that would have also fit in pretty good
System. Out.print('' U R GREAT MAN! '') ;
Thank you,Bro
Thanks, I think this will be more useful for my puzzle game than using all that code from other game development videos :)
Thnk u Bro
thank u
72th. Thank you, ma Bro Sensei
u a best. ty!
Hi! I have a problem:
My code is the same but I can't see the line (like at 4:00). The line became visible only if I call the repaint() method in the paint() method after the drawLine() call. Can you explain this problem, please?
***
EDIT: I see that the issue could be fixed by calling the super.paint(g) method at the beginnin of our overriding method.
***
After that, I would be grateful if you did a video to explain something about BufferedImage, BufferStrategy, VolatileImage end/or similar. And it would be very interesting and useful if sometimes you explained some efficiency information just to understand which class is more suitable for our use.
Thank you!
sounds good
@@BroCodez thank you!
15:00 Reminds me of Bill Cipher
I love your videos but i have a question is there a way to draw on a panel without creating a new class and extending it to JPanel if there is a way help pls
Algorithm
Thank you!
thanks a lot bro!
How is the paint function invoked without calling it? is it because of the new java functionality?
It's called automatically in the background when you create a component
Hello. How can I get a reference to the panel to call the paint function from main? I need to pass through a graphics object but I can't
This is how I fixed it, created a method to return the instance of panel in the MyFrame class:
MyPanel getpanel(){
return panel;
}
On the MyPanel class, I created a new method to pass into the data I want to use to draw onto my panel:
protected void drawelevators(myarray[] _myarray) {
myarray= _myarray;
repaint();
}
By calling the repaint function, this function is called for painting on the panel:
protected void paintComponent(Graphics g) {}
on the main thread, I created instances to the the panel object like this:
MyFrame frame = new MyFrame();
MyPanel panel = frame.getpanel();
Then I called the function I talked about above:
panel.drawelevators(myarray);
Ehhhh so I did this and the ImageIcon doesn't seem to be able to import my images. However, there is another way I learned using the BufferedImage thingy and then surrounding it with try and catch in the constructor. The image works fine with that method but not for the imageicon method like you use, am I missing something?
Thank you for all your teachings by the way :'>
how do u create the new class MyFrames?
Who else heard "Let's draw a pokeball" and went and drew a detailed pokeball? xD
Here's my Pokeball 😂:
g2D.setPaint(Color.red);
g2D.drawArc(200, 0, 100, 100, 0, 180); //draw a half circle
g2D.fillArc(200, 0, 100, 100, 0, 180);
g2D.setPaint(Color.white);
g2D.drawArc(200, 0, 100, 100, 180, 180); //draw a half circle
g2D.fillArc(200, 0, 100, 100, 180, 180);
g2D.fillOval(230, 30, 40, 40); //fill a small circle inside the big circle
g2D.setPaint(Color.black);
g2D.drawOval(200, 0, 100, 100); //draw an outline: outside circle
g2D.drawOval(230, 30, 40, 40); //draw an outline: middle circle
g2D.drawOval(240, 40, 20, 20); //draw an outline: inside circle
g2D.drawLine(200, 50, 230, 50); //draw a line inside the ball
g2D.drawLine(270, 50, 300, 50); //draw a line inside the ball
finally a non hindi tutorial
is it posible to draw tilesets, like only a portion of an image to be displayed?
I have essentially the same code as in the video for printing an image onto a window, but when I print a 320x240 image onto a 320x240 panel, it lowers the resolution of the image significantly. I can't figure out why it's lowering the quality of the image so much. Is there some in between step that the printing takes that does this, and if so can I avoid it?
Hi Bro,
Loving these vids. I have a quick question..
How do I set up eclipse to show the arguments like yours.
yours: g2d.drawArc(x, y, width, height, startAngle, arcAngle);
mine: g2d.drawArc(arg0, arg1, arg2, arg3, arg4, arg5);
If anyone knows what setting I need to enable so the argument tips look like this.
Thanks in advance :)
Try IntelliJ IDE ;D
I have question, how to update this method, or delete this is graphic object?
Why do we need an array of Integers when drawing the triangle?
Hello guys, can someone explain to me, why i don't get the proposals shown at 3:18 ? I only get proposals like equals(), getClass(), hashCode(), wait(), etc. but nothing like drawLine, setPaint, etc. :(
hi, could you talk about the *intersects* function.
thanks
Why my eclipse content assist didn't tell any of drawing method when i type g2d. ?
Does this support multithreading, python didn’t so that’s why I’m asking before I start my project lol otherwise I’ll have to scrap the graphics which would really suck
Its too late, but can I change a background color of my window?
I was trying to copy the "paint" method but somehow it gives me the error: empty parameter field (I guess because of "g" ). What have I done wrong?
Any way to add a event listener to this?
How come you do not need to call paint(); ?
Hi to all. I'm having a problem launching this. I copied it almost exactly as coded, with different class names and different shapes. I keep running the package all three files are in as a Java application and it's not showing a window. No errors but that's about it.
EDIT: Never mind, I fixed it. My version of Main was opening panels rather than the frames. Thanks for the video, you're really saving my bacon on my undergrad thesis.
Can someone explain me why we don;t invoke method paint but it works?
hello can someone help me.
when i run my program, my jframe displays plain black color . what is the problem?
I have no idea why I cannot cast "Graphics g" as a Graphics2D. :(
It says: "Graphics2D cannot be resolved to a type" and this Exception shows up when I run the program:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Graphics2D cannot be resolved to a type
Did you import Graphics2D at the top of your main class's file? That'd be the import java.awt.Graphics2D line at the top of the java file shown in the video.
Make sure your imports are correct and that you've imported both Graphics and Graphics2D and then cast Graphics g as Graphics2D in your program.
@@dusklycanrocvlogs Wow, I actually forgot to import java.awt.Graphics2D
Problems solved, crisis averted
Thanks a lot! 🙏
why we cant use JPannel in MyFrame class rather than create a different class?
for code readability. If you want to, there is no problem with that. Once you refer this after 5-10 years, it would be hard to read all of that code, or it could be difficult to read for a colleague.
I think thumbnail had reversed lmao
than how to draw more than 1 polygon in 1 applet coding?