Java Programming Tutorial - 84 - Drawing Graphics

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 360

  • @dimitriouchemistry2215
    @dimitriouchemistry2215 Před 5 lety +2

    I love your videos! They are short and sweet. You do one thing in each video and you keep it short. It makes it really easy to learn one thing each day and not get overwhelmed. Thank you for making these.

  • @danegonzales5651
    @danegonzales5651 Před 8 lety +1

    You just saved me, Bucky. I've been watching your videos since I started programming. It's 3:36am and I'm still awake 'cause I didn't pay attention on our last Java class. THANK YOU VERY MUCH.

  • @lukesanchez9961
    @lukesanchez9961 Před 10 lety +6

    You, sir are a flat out genious!!! I am filled with gratitude! Thank You for making this tutorial, and keep up the good work!

  • @ItsTheJackpot
    @ItsTheJackpot Před 9 lety +87

    For anyone that has done this in a class called "Graphics" and getting errors: Don't call your class Graphics.... xD

    • @u2withorwithoutyou
      @u2withorwithoutyou Před 8 lety +16

      People like you make this a world worth living in

    • @SaifXPro
      @SaifXPro Před 7 lety +4

      yeah, i already done that xD
      Thanks

    • @noctua7771
      @noctua7771 Před 7 lety +2

      Lifesaver!
      Thanks

    • @gasparcoding
      @gasparcoding Před 5 lety

      Here is a video to create free hand painting in java:
      czcams.com/video/ifVf9ejuFWI/video.html

    • @sallylauper8222
      @sallylauper8222 Před 3 lety

      @nath6161 nath6161 How about 'Melon?'

  • @ahmedashraf5724
    @ahmedashraf5724 Před 9 lety +3

    you know why everyone loves your channel ... cause you make java more fun :D love you man .

  • @Handle_EzSubs
    @Handle_EzSubs Před 9 lety +61

    For those who may still be confuse, I made my own comments in the source code.
    package Class;
    import java.awt.*;
    // ^---Contains all of the classes for creating user interfaces and for painting graphics and images.
    import java.awt.event.*;
    // ^---Provides interfaces and classes for dealing with different types of events fired by AWT components.
    import javax.swing.*;
    // ^---Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.
    public class Class extends JPanel {
    // ^---Extends JPanel to use the frame

    public void paintComponent(Graphics g){
    // ^---You need a paintComponent method to paint pictures
    super.paintComponent(g);
    // ^---You need to equip the variable g into super.paintComponent to draw pictures
    this.setBackground(Color.yellow);
    // ^---This sets the background color
    g.setColor(Color.BLUE);
    // ^---This sets the color you want to use
    g.fillRect(0, 0, 10, 10);
    // ^---This draws a rectangle using the color you selected
    g.setColor(new Color(190,81,215));
    g.fillRect(11, 11, 10, 10);
    g.setColor(Color.RED);
    g.drawString("This is some text.", 21, 21);
    // ^---This displays a string using the color you selected
    }

    public static void main(String[] args) {
    JFrame f = new JFrame("Title");
    // ^---This creates a frame to hold the graphics
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // ^---This exits the program when you close the window
    Class graphics = new Class();
    // ^---This creates an object so you can access methods outside of the main method
    f.add(graphics);
    // ^---This adds the object to the frame
    // ^---I think since paintComponent is the only method outside of the main method...
    // ^---...the objects finds it, and adds it the the frame...or something...
    // ^---This part kind of confuse me. It creates the object, but then it add the...
    // ^---object to the frame without telling it which method to use.
    f.setSize(300,300);
    // ^---This sets the size of the frame
    f.setVisible(true);
    // ^---This sets the frame so it's visible
    }
    }

    • @pandelissymeonidis4227
      @pandelissymeonidis4227 Před 8 lety

      This appears:The serializable class Class does not declare a static final serialVersionUID field of type long

    • @eliasbouhout1
      @eliasbouhout1 Před 7 lety

      +Pandelis Symeonidis Just click on the error icon on Eclipse and select "Add default serial version ID".

    • @mohammedalaanzy8059
      @mohammedalaanzy8059 Před 6 lety

      Thanks a lot for source code

  • @VJScope
    @VJScope Před 10 lety +12

    Notice: This is a bit different than normal coordinate system. The bigger the y is, the lower the coordinate point is (normal coordinates tell us that bigger value y is, the higher the coordinate is).

  • @pc3492
    @pc3492 Před 6 lety

    THANKS!!! This is the only good example I've found that doesn't have errors!

  • @StanlyHD
    @StanlyHD Před 9 lety +6

    why do he need to import java.awt.event.*; when he already imported java.awt.*; ?

    • @MrOlympus223
      @MrOlympus223 Před 9 lety +7

      java.awt and java.awt.event are two different imports. java.awt.* does not include java.awt.event

    • @bartolj.4502
      @bartolj.4502 Před 9 lety +1

      MrOlympus223 yes i was curious about that too, but i figured it out by myself ;)

    • @Swaelo
      @Swaelo Před 9 lety

      MrOlympus223 But he put a wildstar at the end of the java.awt import, so it imports all its children automatically.

    • @lukasschmidt2478
      @lukasschmidt2478 Před 8 lety

      +StanlyHD I know your comment is old but i am still going to answer: If you saw every video and listened to everything he said, you would know.

    • @Swaelo
      @Swaelo Před 8 lety

      +Lukas Schmidt It's episode 84, you really expect people to have seen them all?

  • @kilduff8888
    @kilduff8888 Před 7 lety +12

    "You should know this if you ever took a math class if your life" - Bucky

  • @christoiMc
    @christoiMc Před 13 lety +3

    @pspiso123 Yes, the super method is just the object of the superclass, JPanel. Without extending it, you can just call it using
    JPanel panel = new JPanel();
    panel.paintComponents(g);
    rather than
    super.paintComponent(g);

  • @adaptableant6899
    @adaptableant6899 Před 4 lety +2

    I love how he says "sweet graphics". It's great xD

  • @swisstrucker
    @swisstrucker Před 15 lety

    I really like your tutorials. We have at school java but till I saw your vids I didn't understand it. You make it very well and explain it perfect.
    Thanks

  • @xVerbati
    @xVerbati Před 13 lety

    I think the reason that bucky is a better teacher than some college professors is because some teachers have a "knack" for teaching, and saying what they think others will understand, but that doesn't mean all teachers that know java, also know how to teach "well". idk just a thought

  • @anurag8725
    @anurag8725 Před 7 lety +1

    Why do we need to add a JFrame object in the main class.? We never did that before. Is it because in all earlier GUIs we extend to JFrame but here we extended to JPanel?

  • @netflicks4020
    @netflicks4020 Před 8 lety +3

    For anyone that gets the error with super.paintComponent(g); you have to make sure that you're inheriting JPanel and not JFrame.

    • @TehObLiVioUs
      @TehObLiVioUs Před 6 lety

      WOW, THAT FIXED MY PROBLEM.
      I believe I was having another error or exception, but this fix still fixed my program.

  • @andreleao.prodemge
    @andreleao.prodemge Před rokem

    Hello how are you? Can anyone help me on how I can use Graphics2D other than using JFrame, JPanel or Applets? So, my project is web, I need the drawing to be rendered in a DIV, HTML element. Can someone help me? I've looked on many websites and videos, but they all just talk about JFrame, JPanel, Applets...

  • @Bedocalaway
    @Bedocalaway Před 7 lety +4

    You're hilarious 😂 thank you for everything Bucky

  • @caposolomon8745
    @caposolomon8745 Před 4 lety +1

    Error: Main method not found in class Test, please define the main method as:
    public static void main(String[] args)
    or a JavaFX application class must extend javafx.application.Application

  • @jdims651
    @jdims651 Před 7 lety

    Hi, i tried to run the program but i only got a white screen, not rectangles ; there is a problem and its about the p component, it tells me "null" or something like i did not initialize the component called p

  • @TheValkyron
    @TheValkyron Před 7 lety

    any difference between canvas class and jpanel class as far as making a window with some images goes? I've been told jpanel is a component of a jframe (or a window as i understand it in layman terms) and a canvas object is added to that component. So so far i think that you use .add(canvas) on a jframe with the canvs having an overriden paint method. but by simply changing class extension from canvas to JPanel, and paint() method to paintComponent() I see the same result. can anyone explain why? does this video's way make replace an existing default jpanel from the jframe and paintComponent() puts a canvas on there for us? or am I completely off the rails?

  • @Xy-gx8ou
    @Xy-gx8ou Před 6 lety +1

    I sat down for a while but i cant figure it out by myself (dumb? -_-) How can i access the "p" variable from another class in order to make draw calls from this class?

  • @sandstonewater
    @sandstonewater Před 7 lety

    Thank you so much! Clear, simple intro to Java drawing!

  • @Samad00790
    @Samad00790 Před 3 lety

    for some reason, the paint component method is coming up as red on my intelliJ program? anyone know how to help?

  • @mimitk6642
    @mimitk6642 Před 8 lety +7

    i wrote down the program & I've got no errors but when i run it nothing comes out .. help me out !!

    • @brunohass2436
      @brunohass2436 Před 7 lety +1

      Notice that the main class is different from previous videos.

    • @sreenarendranathgoparaju7362
      @sreenarendranathgoparaju7362 Před 7 lety +1

      me to help me pls.............

    • @swankitydankity297
      @swankitydankity297 Před 7 lety

      make sure it's the exact same as in the video and you should still get what he got. if youre making your own code, make sure that you change the color to something that isn't white

    • @almuntasirabir4511
      @almuntasirabir4511 Před 7 lety +1

      did u spelled "texct" wrong? :D

  • @LPSlasher
    @LPSlasher Před 13 lety +1

    Oh boy oh boy OH BOY!
    Just 3 tutorials away to finish this beautiful *cough* beginner *cough* journey !!!!!!!!!! :D

  • @cpuwrite
    @cpuwrite Před 5 lety

    I am looking to write a hex-based board game. For that, I need the basic tile operations: read from file, blit to screen, write to file. I have looked all over for them. There are plenty of code samples to do this with square "tiles," as they're called, but I can't find anything that will do this with hexagons. I'm currently looking at something called "mapy," but it's confusing.
    Any pointers would be appreciated.

  • @thezombies100
    @thezombies100 Před 10 lety

    paintComponent(Graphics g) is the method of Jpanel. We are overriding it (method overloading) and its called automatically when we override, you don't have to worry about initiating it.

  • @borrosebi
    @borrosebi Před 9 lety +7

    i copy exactly the same code but i can't see anything and i don't get any errors, someone having the same prob here?

    • @AliShahbaz7
      @AliShahbaz7 Před 8 lety

      +Sebastian Borromeo I AM

    • @AliShahbaz7
      @AliShahbaz7 Před 8 lety +10

      +Ali Shahbaz It's probably because u spelt "paintComponent" wrong.

    • @wujosiah8090
      @wujosiah8090 Před 8 lety +2

      exactly I typed pain component

    • @camerongoddard3846
      @camerongoddard3846 Před 5 lety

      Yeah i did "PaintComponent" for one and "paintComponent" for the other. Thanks for the tip!

  • @navylaks2
    @navylaks2 Před 12 lety

    I realy admire your patience that's what i lacked and therefore couldn't become a programmer

  • @miapeanisesmall643
    @miapeanisesmall643 Před 9 lety

    eclipse is acting like i dont have graphics or graphics2d, what is the proper import for this, or is there an install im missing? helphelphelp

  • @EvaporatedBoy
    @EvaporatedBoy Před 8 lety

    I don't understand the use of the line "super.paintComponent(g);"
    My program runs fine without this line.
    Also, I tried changing all the "paintCompenent"s to "paint" and the program also runs fine. Why is that? Thanks in advance for any help!

    • @nickysteve5467
      @nickysteve5467 Před 8 lety

      When you don't put in that line of code is because it wouldn't repaint otherwise. when moving graphics around by changing the x and y values, without that code you would see where the graphic previously was, but with that line of code the previous instance of the graphic would change every time it's updated.

  • @Hildoz2
    @Hildoz2 Před 13 lety

    @theMacBoy11 If you google "java graphics api" you can see a list of the methods you are able to use. If it is possible, then you will see a method like setColor(*your hex thingie*). If not, then it's either not possible, or the method is located in one of the parrent classes (Graphics extends other classes).

  • @kiki1299able
    @kiki1299able Před 9 lety

    +thenewboston i have been following your tuts as far as the completion of having the images blink(close eyes open eyes). since then i have used your code to keep the screen settings and now i trying to draw two rectangles on the screen, i got thru with that. is there anyway to make it clickable?(the rectangles) using the graphics class?

    • @bartolj.4502
      @bartolj.4502 Před 9 lety

      Ahaiziah Shako yes there is checkout some game programing tutorials and you'll learn it

    • @kiki1299able
      @kiki1299able Před 9 lety +1

      thanks will check it out

  • @hossamnasser9717
    @hossamnasser9717 Před 4 lety

    I didn't write the line of code super.paintComonent(g); And the program worked. What is it useful for ?

  • @YeyoPrince
    @YeyoPrince Před 10 lety +2

    Cool feature in IntelliJ, if your setting custom colors a sample of the color appears to the left of the line your coding on.

  • @harivigneshr6244
    @harivigneshr6244 Před 2 lety

    Thank you for posting this video. What would be the Java code to write text into an existing word (.docx) file?

  • @fmfm579
    @fmfm579 Před 7 lety

    can some explain the code below please, why do we have x,y in constructor parameter initialised with axes of the top ones.
    int x=10;
    int y=10;
    public Constructor(int x, int y){
    this.x=x;
    this.y=y;
    }

  • @Fangornmmc
    @Fangornmmc Před 13 lety +1

    He uses eclipse i recommend you watch the tuts in the right order youll learn a lot and it should be extremely easy to follow along

  • @MarlonConstance
    @MarlonConstance Před 8 lety +1

    hi bucky for the fill Rect Function do i have to specify int for the variables??????i

  • @aymansaid1253
    @aymansaid1253 Před 7 lety

    I have to draw a cartoon character for a school project and *I have a question.* How to I pass multiple parameters to the paintComponent method. I tried this:
    public void paintComponent(Graphics g, Graphics g2) {
    Graphics2D pearl = (Graphics2D) g;
    Graphics2D wings = (Graphics2D) g2;
    I wanted to draw the different parts separately, however this printed nothing.
    public void paintComponent(Graphics g) {
    Graphics2D pearl = (Graphics2D) g;
    This however worked just fine. The issue is that I've already drawn a big part of my character, but I need to draw parts behind what I already have, and whenever I do that, things like .rotate() and .translate() will mess up everything that comes after, so I was hoping I could draw them in a separate method or something (I'm still rather new to Java so forgive my possible errors in terminology).
    I'd REALLY appreciate if you could respond asap. Currently drowning in other homework and I had to put this aside!
    P.S.
    I extended JComponent into the class. not JPanel.
    The character I'm drawing is the pokemon Palkia.
    cdn.bulbagarden.net/upload/thumb/6/66/484Palkia.png/250px-484Palkia.png
    I've already drawn the big shield thing with the pearl in the center on her shoulder, but I now need to draw the three wings that are behind that and that go rightwards. I don't know how to .rotate() those wings without rotating what I have as well.
    Thank you

  • @batrachin
    @batrachin Před 9 lety

    Hi focky (how do you spell it)
    I'd like to draw an arrow between 2 buttoms to represent a graph (vertex-edges) do you have any suggestion for me? thanks dude!

    • @bartolj.4502
      @bartolj.4502 Před 9 lety

      guille vazquez yes i have suggestion you can create arrow image in photoshop and put that picture in your program ;)

  • @sophiachergui6212
    @sophiachergui6212 Před 4 lety

    What happens if you don't put the super.paintComponent(g) line? I didn't use it in any of my drawings before and they still worked.

  • @danaonline2007
    @danaonline2007 Před 9 lety

    Could you please tell me what text editor are you using in this video? It looks pretty cool. I'm using plain old Notepad++ and obviously it doesn't give any suggestions:(...

  • @MegaMaliak
    @MegaMaliak Před 7 lety

    hi, i need to draw standard normal diviation, whats the easiest way to draw that line? o do i actually have to make 100ths of drawLine statements and then sort each dot on the line?

  • @charlesrichard5756
    @charlesrichard5756 Před 6 lety +1

    I loked at the date it was uploaded and i thought it said 2019 and was like "I knew my schedule was off but WOW I'm behind on EVERYTHING."

    • @gasparcoding
      @gasparcoding Před 5 lety

      Here is a video to create free hand painting in java:
      czcams.com/video/ifVf9ejuFWI/video.html

  • @FirstNameLastName-tc2ok

    Hi! Just a confused beginner from video 37! Hope to get to this video some time!

  • @MarlonConstance
    @MarlonConstance Před 7 lety

    you never showed us how to download the java 2D library when i go on the site i am seeing lots of links and still cant access the libraries pls help it;s firetrucking frustrating man????

    • @BucifalulR
      @BucifalulR Před 7 lety +1

      Doesn't that come included with Java? Hopefully I'm not wrong :).

  • @omiorahman6283
    @omiorahman6283 Před 7 lety

    regarding 2d character movements If my sprite sheet is horizontal would it cause problems?

  • @synenergy7414
    @synenergy7414 Před 9 lety +2

    I've looked at his video and my work over and over but I can't find my mistake. I copied exactly what bucky did but my GUI is blank. My program doesn't even give me errors. Anyone know what could be wrong?

    • @mtho5889
      @mtho5889 Před 9 lety +1

      I've got the same problem

    • @kuite922
      @kuite922 Před 9 lety

      Mtho Kunene instead of extends JPanel try extends JFrame, I don't know why it works but it does

    • @Aadarsh155
      @Aadarsh155 Před 9 lety

      SynEnergy You have type what is there in the main method in the bucky class...not whatever in the peaches class....
      there , there are certain code which is required to set up the JFrame/JPanel !

    • @synenergy7414
      @synenergy7414 Před 9 lety

      Thanks for the help. :)

    • @Ham1001dy
      @Ham1001dy Před 9 lety

      SynEnergy lol took mea day to realize I left out f.add(p);

  • @dawoodchaudary8736
    @dawoodchaudary8736 Před 8 lety +1

    the step super.PaintComponent(g);
    its giving me error saying
    graphics.Graphics canot be converted to java.awt.graphics what thats suppose to mean any one help

    • @mmaxxonn
      @mmaxxonn Před 8 lety +1

      +Dawood Ahmed PaintComponent is wrong, use paintComponent

  • @rohankhanna8753
    @rohankhanna8753 Před 8 lety

    can we write g in the place of this ?? both will do same work or theres some diff.

  • @Cartier1288
    @Cartier1288 Před 11 lety

    im just a complete beginner with java (i havent been following these tuts), but i believe since you are importing those methods, you have to run them off the same name, so i believe they have changed the name of that method from the time that this tut came out and the time that you are doing this!

  • @shackj2
    @shackj2 Před 12 lety

    Tìm hôm qua tới giờ mới thấy. Thank you very much.

  • @karthigeyan8012
    @karthigeyan8012 Před 4 lety

    Bro only white page is displaying the out screen .what the promble I don't know bro😭😭

  • @ConMahaff
    @ConMahaff Před 14 lety

    @ConMahaff alright found the problem, spelled Component wrong, my mistake

  • @Void-in2pz
    @Void-in2pz Před 9 lety

    how can i delete components from the window (JFrame ) not closing the window, just by pressing some button ?

    • @vasdreg17
      @vasdreg17 Před 9 lety

      +Void U can just repaint something else.

    • @joshuagort5905
      @joshuagort5905 Před 9 lety

      +Void I would get the background color and put a rectangle over the thing you want to remove.

  • @garrettbarton5240
    @garrettbarton5240 Před 4 lety +1

    "Make sure you spell tecxt wrong or it won't work" haha I love Buckey

  • @ConMahaff
    @ConMahaff Před 14 lety

    so weird, after I compile it (no errors) nothing prints out on the screen, its just an empty box. I've checked my code like 10 times now, still haven't found a problem. Has anyone else gotten this?

  • @anastasiiababoian8531
    @anastasiiababoian8531 Před 6 lety

    such a nice how u talk and explain the stuff

  • @arekwittbrodt
    @arekwittbrodt Před 11 lety

    If I correctly understand: whenever I want to draw something, I should call repaint() and all instruction for drawing have to be in the paintComponent() function?
    But how that function know, what to draw? Should I pass somehow specific instruction (in component's public variables?) to that function? Or should I biuld my program in such way, that everything is in the paintComponent()?
    I have in mind a program which takes from user some info and then draw something based on that data.

  • @eliasbouhout1
    @eliasbouhout1 Před 7 lety

    If your program doesn't work maybe you could resolve that writing:
    "public class Example extends jFrame" instead of the
    "public class Example extends Jpanel" that he shows in the video,if that doesn't work try
    "public class Example extends JComponent".
    If you get an error "The serializable class Example does not declare a static final serialVersionUID field of type long" simply click on that error icon on the Eclipse IDE and click on "Add default serial version ID".

  • @Shamanmagic95
    @Shamanmagic95 Před 13 lety

    if some one could tell me why mine is not working I have
    public void paintComponent(Graphics g)
    as the error in my code saying that it is a bad class file.
    If somebody could tell me the problem i would have much thanks!

  • @ritikthakur2445
    @ritikthakur2445 Před 6 lety

    We didn't create the object of Graphics class. How can we access all the methods from Graphics class??

  • @Eckister
    @Eckister Před rokem

    ... does the object make the final drawing that of a "g-string"?
    .
    .
    .
    .
    .
    .
    I'll let myself out...

  • @Hildoz2
    @Hildoz2 Před 13 lety

    @theMacBoy11 I did a little Googling, and I saw that if you make a new Color class you can specify the HEX number directly in the constructor's parameter like this: java.awt.Color colorNameHere = new java.awt.Color(0xFF0096); as long as you remember the '0x' before the HEX code.
    You can then use that color object with the g.setColor(colorNameHere); to use the example in the video to change to color.
    Have fun! :D

  • @void_presence
    @void_presence Před 13 lety

    I prefer BlueJ, it has a very simple interface and shows graphical relationships between classes (such as inheritance and other dependencies), i've also started to use NetBeans also.
    Also, BlueJ doesn't irritate me by constantly suggesting stuff, yet it still color-codes key words.

  • @TheViolinCalamity
    @TheViolinCalamity Před 12 lety

    'My ultimate goal is to make computer games, and we can't make computer games without SWEET graphics' - quote of the day by a mile, although I'm sure the guy who made pong said the same...

  • @Chrisymcmb
    @Chrisymcmb Před 7 lety

    @thenewboston
    I'm a bit confused. This looks a bit like a recursive method:
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    }

    • @Elendrial
      @Elendrial Před 7 lety +3

      The "super" part means it runs the parents class's paintComponent(g) method (the parent class being JPanel in this case, as that is the class that is extended), so rather than just running your code, some of the java code is run first, probably to make sure everything's initialised properly.
      Hope this clears up your confusion :)

  • @AlexDiru
    @AlexDiru Před 13 lety

    Wow this is great, looking to learn Java before starting Uni, and I'm coming from C++. Just read Java for Dummies (awful book, but luckily the transition from C++ to Java is easy) and was looking for where to go next, this seems like a good start :) Thanks :)

  • @karan_2892
    @karan_2892 Před 12 lety

    hello people these are the imports you need
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.JPanel;
    import javax.swing.JComponent;
    import javax.swing.JFrame;

  • @void_presence
    @void_presence Před 13 lety

    I prefer BlueJ, it has a very simple interface and shows graphical relationships (such as inheritance and other dependencies), i've also started to use NetBeans also.
    Also, BlueJ doesn't irritate me by constantly suggesting stuff, yet it still color-codes key words.

  • @ohboyd
    @ohboyd Před 11 lety

    I have to add the import "java.awt.Graphics" because if I don't then I get errors on the setColor and fillRect methods and the g as the argument for paintComponent. Anyone know why?

  • @thezombies100
    @thezombies100 Před 10 lety

    Yes you can! But before you proceed further with android make sure you have a strong understanding of the basic android development. Android uses Java but to develop apps for it you need to read a lot of documentation to know how to use Android API's which is not related to java.

  • @EnderfanGaming
    @EnderfanGaming Před 4 lety

    thank you so so so much i couldn't figure this out but you helped me!

  • @Shamanmagic95
    @Shamanmagic95 Před 13 lety

    @EarthWorms77 I got it, i had to import another file. Now I am doing graphics like a boss!

  • @peterhind
    @peterhind Před 12 lety

    When a window becomes visible (uncovered or deminimized) or is resized, the "system" automatically calls the paintComponent() method for all areas of the screen that have to be redrawn.

  • @euphoricandpr
    @euphoricandpr Před 11 lety

    Same thing here. I reread my code so many times before deciding to check the comments.

  • @SOAD525
    @SOAD525 Před 12 lety

    how would i make a square appear if i use this in a action listener? say if i press a button. i cannot figure this out!

  • @gamalytical
    @gamalytical Před 13 lety

    Can anyone explain to me where the paintCompenent method is actually called? I'm confused as to how it is being used even though it is not called as part of the t object in the main method.

  • @keeshottinga2729
    @keeshottinga2729 Před 8 lety

    In bucky.java:
    f.setLocationRelativeTo(null); // Pop up window in the middle.

  • @n8style
    @n8style Před 13 lety

    @gamalytical I think what's happening is the paintComponent method in the Peach class is overiding the paintComponent method in the JPanel class, and it gets called whenever the JPanel needs to be repainted.

  • @pekwk45
    @pekwk45 Před 11 lety

    paintComponent is called automatically when setVisible is called. This in turns calls repaint which calls paintComponent.
    PaintComponent belongs to JPanel class yes.

  • @cellfreezer
    @cellfreezer Před 12 lety

    Thanks, man. I changed the color like mad and wondered why the canvas is still grey.

  • @abdulsattarmari
    @abdulsattarmari Před 12 lety

    Hey i was wondering why it we come 'down' in "y" axis in programing?!?? but in maths when we say y is 25 units it means we go to UPWARD. but in computers we come DOWNWARD
    WHY!???

  • @IvanVinski2009
    @IvanVinski2009 Před 12 lety

    Or simply do this:
    import java.awt.*;
    import javax.swing.*;
    And when you finish all the drawings, press SHIFT + CONTROL + O.

  • @23SuS23
    @23SuS23 Před 14 lety

    this guy is better than my computer science teacher lol

  • @yamika.
    @yamika. Před 4 lety

    a blue rectangle chilling on our screen

  • @crusaders36
    @crusaders36 Před 13 lety

    Why is it I am unable to draw two different instances of the peach. If I draw one it works, if I try to draw another the first one disappears? SOMEONE HELP!

  • @EL-nf2fd
    @EL-nf2fd Před 3 lety

    how to paint circle and square using java.awt.Canvas like drawing it

  • @christianitis
    @christianitis Před 4 lety

    What JDK is this? I keep getting a stack overflow when I do this in JDK13 on JRE14.

  • @Brainiac5
    @Brainiac5 Před 11 lety

    Eclipse just doesnt allow me to run it when i did "f.add(p);" i followed exactly what Bucky typed but i dont know why its not letting me output it

  • @CrackofDoom90
    @CrackofDoom90 Před 12 lety +1

    Loved the "constant" joke :))

  • @toddsales8059
    @toddsales8059 Před 10 lety

    Great work mate - thanks for sharing

  • @Arc72Productions
    @Arc72Productions Před 13 lety

    I added the second class to my main class, with the f.add(p); and I have nothing showing up on my screen still

  • @olivernaeshh6197
    @olivernaeshh6197 Před 7 lety

    can you draw a blue rectangle, and then change the color to red when you click it?

  • @christoiMc
    @christoiMc Před 13 lety

    @riky9031 I don't know, but if you are new to java like I am, I doubt it really matters to be honest. Both should work fine, although you can get both to see for yourself.

  • @RainClark
    @RainClark Před 14 lety

    @scullshot ...Create the action or method for a graphic to be drawn inside the action handler for your JButton

  • @fernandohood5542
    @fernandohood5542 Před 4 lety

    If there is more than one rectangle which one gets filled?

  • @thatsuxbigtime
    @thatsuxbigtime Před 12 lety

    you must do p.add(f) instead of f.add(p). You cannot add a window to a container, only a container to a window