aspose file tools*
The moose likes Beginning Java and the fly likes display image for complete noob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "display image for complete noob" Watch "display image for complete noob" New topic
Author

display image for complete noob

Jon Boyinski
Greenhorn

Joined: Jun 25, 2011
Posts: 2

Hey folks (I just joined here)

I'm on my first week with java and although I have several successful years experience with php/ActionScript 3 I am finding it really difficult to get things done in java. Naturally I've been going through the oracle tuts and anything else I can find (most seem to be just regurgitated oracle tuts) but I find all of them way harder to understand than all the fantastic php and flash/as3 tuts that I learned from many years ago.

Anywho below is some image code straight from oracles tuts.

what I don't understand:
Q1. Nothing is calling the method paint, why is it running? (i think its an inherritance thing but still, I don't get it)
Q2. What if I want to display/line up many images? Is this sample class just for loading/displaying one image and as such i would write another class that keeps calling this class and passes in the image path each time?
Q3. Why can't I find a method called "paint" (lowercase) in the Java6 api?
Q4. In the sample code what is "g" in the paint method? Some kind of object i presume... ??
Q5. Because of the ease of working with images in as3 that I'm used to, I'm tempted to ask... why can't i just do something like: f.add(img); inside the LoadImageApp() method
Q5. Why is netbeans telling me to add an @override annotation with the paint method? after reading about overrides for an hour this is what has lead me to believe that the method:paint is overriding an actual java class... I still don't get it that's just what i gathered from reading. ???

thanks for tolerating my ignorance!

>>>sample image code



Thank you
Cory Hartford
Ranch Hand

Joined: May 16, 2011
Posts: 82

Hi and welcome. I'm no expert but I'll try and help. Take it with a grain of salt because I am still learning too.

1)Nothing is calling the method paint, why is it running? (i think its an inherritance thing but still, I don't get it)
Since you are extending the Component class, one of the methods available to you is the paint(Graphics g) method. You are either over-riding it by implementing your own code or it was an abstract method that is defined in the Component class. In fact I just looked it up and it is a method defined in Component and you are overriding it here. Now the reason it is called is that when you use one of the other methods (add(), setVisible() I am not sure which) they have a call to the paint method in the Component class. You don't see it but since you overrode the paint method thats what is being used.
webpage

2) What if I want to display/line up many images?
In swing you have to use a layout manager. There are different kinds that do different things. As an example the grid layout tiles objects like a tic-tac-toe board. I don't know if there applicable in awt. I think they are since Swing uses awt as a base (I think) but not sure.
gridLayout

3)Why can't I find a method called "paint" (lowercase) in the Java6 api?
I think because it is part of the component class. Check this out. Scroll down to see the methods available. Paint is one of them.
Copmonent Class

4) In the sample code what is "g" in the paint method?
In the paint method, you are passing a Graphics object to that method (well not you but awt is when you ask it to). That Graphics object is know as 'g' within the paint method. That way you can pass a bunch of different named Graphics objects to the paint method and it'll operate the same way regardless of the Object name.

5)Because of the ease of working with images in as3 that I'm used to, I'm tempted to ask... why can't i just do something like: f.add(img); inside the LoadImageApp() method

I'll leave that for the multilanguage studs to answer.



6) Why is netbeans telling me to add an @override annotation with the paint method?

This goes back to question 1. You overrode the paint() method in your code. The method exists already in the Component class but you are saying "I don't want that implementation of paint(); I'll write my own"


Hope that helps!


‎"The greatest of all weaknesses is the fear of appearing weak." - JB Bossuet
Jon Boyinski
Greenhorn

Joined: Jun 25, 2011
Posts: 2

@cory
I think it will. thanks. Give me a day or two to digest the info, experiment, and research it further... I'm sure i'll have some more questions.
+my wife is hanging around which equates to a coder's speedbump
...until then; thanks again.
Cory Hartford
Ranch Hand

Joined: May 16, 2011
Posts: 82

Jon Boyinski wrote:
+my wife is hanging around which equates to a coder's speedbump



Seriously. My wife does that to; plus I have a 1 year old that likes to type on my laptop while I am so I totally get it. Good luck with the experimentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display image for complete noob