Tim McGuire wrote:can you post the code you use to start this one up?
Paul Clapham wrote:No, that is the right solution.
The wrong solution is to try to change the icon's colour. That's because there is a hidden assumption in that solution, namely the assumption that an icon has "a" colour. Obviously that isn't the case, an icon is an image which can consist of many colours. Which means that there isn't going to be a method to change an icon's colour.
Paul Clapham wrote:Changing the icon at run-time sounds like a better idea. After all if you look at real traffic lights, they have more than just colours. Sometimes they have green arrows as well as green circles, at least where I live they do. And sometimes they flash on and off.
Aleksey Vladimirovich wrote:I can't get few things...
When any class implements this interface, what is the connection between a regular method (this one: void paintIcon(Component c, Graphics g, int x, int y)), which was overriden from interface and the constructor of my class? I mean, why this method executes once new instance of object of my class was created (I do not call it explicitely)? And how does my class know what object has been drawn in this method?
Sorry, if the questions are stupid, but I really want to understand
Aleksey Vladimirovich wrote:Guys, could you please answer the second question from my first post? I mean this one:
Aleksey Vladimirovich wrote:I can't get few things...
When any class implements this interface, what is the connection between a regular method (this one: void paintIcon(Component c, Graphics g, int x, int y)), which was overriden from interface and the constructor of my class? I mean, why this method executes once new instance of object of my class was created (I do not call it explicitely)? And how does my class know what object has been drawn in this method?
Sorry, if the questions are stupid, but I really want to understand
luck, db
There are no new questions, but there may be new answers.
Paul Clapham wrote:No, that is the right solution.
The wrong solution is to try to change the icon's colour. That's because there is a hidden assumption in that solution, namely the assumption that an icon has "a" colour. Obviously that isn't the case, an icon is an image which can consist of many colours. Which means that there isn't going to be a method to change an icon's colour.
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:Read through the source of javax.swing.plaf.basic.BasicLabelUI. The part you're interested in is on line 150 in my version of the sources. (Just in case you don't already know, you can find that in the src.zip file in your JDK folder.)
An Icon can have several states, but setting a different Icon isn't noticeably more expensive. Also, if an Icon implementation changes its appearance, it will still be necessary to call repaint() on the Component that displays the Icon as the new appearance will only be seen after repainting.
luck, db
There are no new questions, but there may be new answers.
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:A Timer without an ActionListener is like a car without an engine. There's a tutorial linked from the API for javax.swing.Timer. Go through it.
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|