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); } }
@BroCodez4 жыл бұрын
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); } } //---------------------------------------------------------
@DiamantOpp9 ай бұрын
Out of all coding related channels on youtube, this is BY FAR the best one.
@programer66642 жыл бұрын
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.
@bluesillybeard3 жыл бұрын
This is a brilliant tutorial! straight to the point (well, ignoring the like & subscribe stuff), very straightforward and easy to understand!
@ozz9613 жыл бұрын
draw rect like get rekt , perfectly explained 🙌 👌
@streelet8647 Жыл бұрын
Thanks for the useful content
@jhanzaibhumayun57823 жыл бұрын
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.
@AkramAtti-jj6yc7 ай бұрын
Nice video !!!!!
@chrismunsonmusic34322 жыл бұрын
Awesome content
@YTSHANKY4 жыл бұрын
As always .. bery good content
@mikloscsuvar6097 Жыл бұрын
This was a good summary on 2D graphics basics. I got this link as a course material.
@Ahmed-iam2 жыл бұрын
Super helpful
@neotericfossil10 күн бұрын
Nice video. Thanks.
@edsiegel53573 жыл бұрын
That was great. the first clear description of how to use 2D graphics i've seen.
@MittenyLewis2 жыл бұрын
cool video bro.
@kenkinyua70363 жыл бұрын
thanks you make learning fun and productive😄
@carriejiang15702 жыл бұрын
Very nice video ! 😀😀
@kemann38153 жыл бұрын
Another great one
@pavelkvasnicka6856 Жыл бұрын
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
@ADAhd663 жыл бұрын
Want to create moving object from one point to other,and thank you for your teaching in a simple and detailed way of explanation
@turhantemizel26829 ай бұрын
Your explanation is brilliant!
@theuser8102 жыл бұрын
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).
@radupurecel33304 жыл бұрын
I'm glad I find your channel! I've learned and still learning so much things in a short time! ^^
@YTSHANKY4 жыл бұрын
KZbin never recommend your videos.. I watch a lot of videos related to programming.. i randomly searched bro code.. and found your channel
@BroCodez4 жыл бұрын
nice!
@pavan_goat Жыл бұрын
Great thanks
@tecso20273 жыл бұрын
Great video, easy to follow and understand. Thanks for uploading!
@tuoivan4374 Жыл бұрын
Thank you for these tutorials!
@nawfalnjm56993 жыл бұрын
thank you for this video . helped me so much to understand GUI
@zed9zed2 жыл бұрын
Great and simple, with no fluff! Thanks much.
@anonimanonim12232 жыл бұрын
Like it!
@neenaelsa99242 жыл бұрын
Thank you so much for the video. Very helpful for a beginner.
@amira669967 ай бұрын
Hey , just want to say that your videos are awesome and this video really helped me , thank you
@eugenezuev73496 ай бұрын
Bro is a Java king
@yoursubscriber69094 жыл бұрын
Really Cool
@dougrattmann57912 жыл бұрын
Great explained!
@MrLoser-ks2xn Жыл бұрын
@marekmacku35262 жыл бұрын
Great video! Thanks alot
@shpatspahiu29292 жыл бұрын
Helpful
@animeshbiswas27542 жыл бұрын
You're awesome. I am learning so much from you. Please keep it up.
@cinderacedr Жыл бұрын
Gave it a like! Thanks man and great video!
@andrewchen8612 жыл бұрын
Thanks for the video!
@redphantom4512 ай бұрын
Thanks dude, might create a personal video to help me re-learn this
@ItsIcedDonut7 ай бұрын
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.
@jfruit63104 жыл бұрын
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.
@BroCodez4 жыл бұрын
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
@yoursubscriber69094 жыл бұрын
I'm first to comment after you 👑
@BroCodez4 жыл бұрын
Here you go: 🥇
@ibrahimylmaz83782 жыл бұрын
thanks bro
@omardumet1203 жыл бұрын
amazing
@virachi275 Жыл бұрын
I love at the begin of this vid that show an image from the game Dragon's Lair
@BRED40k2 жыл бұрын
how do u create the new class MyFrames?
@motototoralabastru27412 жыл бұрын
thank you for this video, it was very helpful :)
@akeimstbernard46033 жыл бұрын
Thank you for this understandable tutorial, you're amazing.
@balaeinstein87104 жыл бұрын
i think this is the best playlist available for learning java graphics . Thanks a lot bro. playlist is not updated?
@honoredegg2 жыл бұрын
72th. Thank you, ma Bro Sensei
@thatnelfy2 жыл бұрын
u a best. ty!
@AsfawYemaneBerhe Жыл бұрын
Thank you,Bro
@zillionere3 жыл бұрын
Good
@belalehner3937 Жыл бұрын
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.
@chzzh66343 жыл бұрын
cool
@GuillinCorp2 жыл бұрын
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
@GuillinCorp2 жыл бұрын
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);
@acminostgien30389 ай бұрын
is it posible to draw tilesets, like only a portion of an image to be displayed?
@mrbadmadable3 жыл бұрын
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. :(
@stephanososten25802 жыл бұрын
Thanks so much for helping me cause I didn't have any knowledge about how to set up an image background.
@ratibor_shevchenko4 жыл бұрын
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!
@BroCodez4 жыл бұрын
sounds good
@ratibor_shevchenko4 жыл бұрын
@@BroCodez thank you!
@JehanSaren Жыл бұрын
sir, next please🙏 cloth simulation
@ElectroGehirn11 ай бұрын
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
@mauriciomachado88553 жыл бұрын
Muito bom. Obrigado.
@davidorevic6651 Жыл бұрын
Why do we need an array of Integers when drawing the triangle?
@emirhanaydncakl8512 жыл бұрын
Thanks
@mahmoudgaber77392 жыл бұрын
thank u
@siddheshss123454 жыл бұрын
How is the paint function invoked without calling it? is it because of the new java functionality?
@BroCodez4 жыл бұрын
It's called automatically in the background when you create a component
@gdbot12 жыл бұрын
I have question, how to update this method, or delete this is graphic object?
@Verzach33 жыл бұрын
Any way to add a event listener to this?
@PhieFty3 жыл бұрын
Why my eclipse content assist didn't tell any of drawing method when i type g2d. ?
@GodmyX Жыл бұрын
Thank you!
@joelrooldemelojunior96123 жыл бұрын
hi, could you talk about the *intersects* function. thanks
@gooseguy1641 Жыл бұрын
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?
@karlpillay8360 Жыл бұрын
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 :'>
@mediadimah223 жыл бұрын
System. Out.print('' U R GREAT MAN! '') ;
@zer0k1line683 жыл бұрын
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);
@oussamaelhousni56653 жыл бұрын
Thnk u Bro
@przemysawmazurek60283 жыл бұрын
Can someone explain me why we don;t invoke method paint but it works?
@iamfunnyguy84682 жыл бұрын
hello can someone help me. when i run my program, my jframe displays plain black color . what is the problem?
@moka82672 жыл бұрын
Thanks, I think this will be more useful for my puzzle game than using all that code from other game development videos :)
@kshau_3 жыл бұрын
15:00 Reminds me of Bill Cipher
@nages11713 жыл бұрын
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
@dausel627611 ай бұрын
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?
@falyarivelo70682 жыл бұрын
thanks a lot bro!
@gamehacker56928 ай бұрын
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
@neurotoxin68023 жыл бұрын
Its too late, but can I change a background color of my window?
@bijikuda31242 жыл бұрын
than how to draw more than 1 polygon in 1 applet coding?
@draft_fusion2 жыл бұрын
How come you do not need to call paint(); ?
@utku13763 жыл бұрын
why we cant use JPannel in MyFrame class rather than create a different class?
@ojaspednekar3 жыл бұрын
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.
@ArrowCraft-k2j Жыл бұрын
Algorithm
@lequangnghi1942 жыл бұрын
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
@dusklycanrocvlogs2 жыл бұрын
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.
@lequangnghi1942 жыл бұрын
@@dusklycanrocvlogs Wow, I actually forgot to import java.awt.Graphics2D Problems solved, crisis averted Thanks a lot! 🙏
@thephoenixsystem67653 жыл бұрын
Who else heard "Let's draw a pokeball" and went and drew a detailed pokeball? xD
@bubblejuiceTV3 жыл бұрын
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 :)
@asher052 жыл бұрын
Try IntelliJ IDE ;D
@lequangnghi1942 жыл бұрын
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
@ziskador3 жыл бұрын
finally a non hindi tutorial
@andreleao.prodemge2 жыл бұрын
Olá, tudo bem? Alguém pode me ajudar em como faço pra usar o Graphics2D sem ser usando JFrame, JPanel ou Applets? Tipo, meu projeto é web, preciso que o desenho seja renderizado numa DIV. Alguém pode me ajudar? Já procurei em muitos sites e todos só falam de JFrame, JPanel, Applets...