Link to home
Start Free TrialLog in
Avatar of stvrich
stvrichFlag for United States of America

asked on

Kindergarten Java question

Please help me understand basic graphics / displays.

I feel kind of silly asking this.
But, any of the books I've got on Java do not explicitly tell me what it is I am asking myself about this Graphics stuff.

And this is something very basic.

All the books I've got just show me the line of code, and then USE the line of code, but since I've begun using java a little... NONE of my texts explain what this line means.  So, I feel like I do NOT understand it.
Yes, I can make stuff print out... and even manipulate output.
But, I don't understand that line.

Please interpret the following code(in english):
<yes, use pretty colored chalk if necessary>

 Graphics2D screen2D = (Graphics2D) screen;

 !!!

I understand that,
   public void paint(Graphics screen) {

is a paint method <that returns no value> in an applet.
And I understand that the paint method is creating a "Graphics object" named "screen".

Then:
I understand you are creating a "Graphics2D object" named "screen2D"...

But:
HOW do you interpret (in english please) what the right side of the equals sign means???

Please spell out the meaning of that line to me, as if you were a Java/Kindergarten teacher and HAD to draw a map... (And then had to LEAD the blind guy anyway).

If you can somehow make me understand these objects.
What I am creating (when I do this).
And what I am DOING (when I do this).
And maybe where values, graphics, printable stuff flows through these objects... I'll be very thankful.

<thank you>

Sincerely




Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

First, you need to know that class Graphics2D is a subclass of Graphics class.
The right side of the equal sign shows that you are explicitly casting a Graphics object called "screen" to a Graphics2D object. Why do we need this? This is because we want to access some member functions of Grahpics2D class which is not defined in the Graphics object. If we directly call the functions using the Graphics object "screen", then there is compilation error.

Since you are creating a new Graphics2D object by casting an existing Graphics object "screen", so the default configuration of the Graphics2D object will be the same as the object "screen".

Hope you understand. IF not, please feel free to ask.
ASKER CERTIFIED SOLUTION
Avatar of Holger101497
Holger101497

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stvrich

ASKER

Hi Guys,

I've been busy lately.
But, I'm reading over your suggestions now.
Avatar of stvrich

ASKER

Yes... !

This is precisely the kind of feedback I need to understand this.

(Obviously I'm still absorbing fundamental concepts, and... )

I'm thankful for your help.

Give me a Day or two to find some time to absorb what you've said... But, I think, Holger, that What you've described to me is exactly the kind of explanation I need.
Avatar of stvrich

ASKER

Yes... !

This is precisely the kind of feedback I need to understand this.

(Obviously I'm still absorbing fundamental concepts, and... )

I'm thankful for your help.

Give me a Day or two to find some time to absorb what you've said... But, I think, Holger, that What you've described to me is exactly the kind of explanation I need.
Avatar of stvrich

ASKER

A have Several <big name> Java books available to me to consult (Sun's -core Java-, Java Tutorial, Java/24 hours, and a couple of certification guides... etc).  And NONE of them have explicitly explained that statment as well as it just was explained here.

It's enough info, that a ~new~ Newbie, like me can be pointed in the right direction, connect the dots, and see what the statement REALLY means, and continue Self Educating.

Thank you very much for your help.

Sincerely
Avatar of Holger101497
Holger101497

Glad I could help :-))

> A have Several <big name> Java books available to me to consult (...etc).
> And NONE of them have explicitly explained that statment as well as it just was explained here.

Possibly, you're looking at the wrong chapter :-)
If you really want to "learn" Java and not just see how you can copy and modify an applet in one hour, you should take a look at the chapters about variables, passing parameters, object-oriented programming (i.e. classes, subclassing and typecasting).
This will be a few day's reading before you really start programming.
Some books, especially the "Get started quickly"-thingies, tend to explain these important things last (or not at all...)

I didn't have that much trouble getting started in Java because I already knew so much about these things from programming Delphi. THERE, however, I remember reading a good 200 or 300 pages in the manuals. They had a really good introduction "from the very beginning". I guess that's the difference between an expensive development tool (luckily much less expensive for students :-) and an essentially "free" language like Java...

Back to the topic: I think programming applets is NOT such a good way of learning Java. Because of the interaction with the browser, much of what's "really going on" is hidden...
Much less entertaining, but much more helpful: write a few little standalone-applications. Try simple one that print messages to the console first and then try getting started with the AWT or even Swing. When you understand these, applets will suddenly be MUCH less confusing (you could call it "simple" then :-))

Good luck,
               Holger