Article View: aus.computers.java
Article #800Re: New to Java
From: Ross Vumbaca
Date: Fri, 21 Apr 2000 00:00
Date: Fri, 21 Apr 2000 00:00
57 lines
2457 bytes
2457 bytes
Hi,
David Belavy wrote:
> Hello Everyone,
> I'm learning to program from the Deitel & Deitel book and I was just
> wondering what the 'g' means in
>
> public void paint (Graphics g)
> {
> g.drawString("String", 25,25);
> }
> What does the g actually refer to?
The above code is a method (aka routine), and is called "paint"
The method requires a parameter. The required parameter needs to be an
object, of type "Graphics" (aka an object of class "Graphics" aka an
instance of the Graphics class)
The "g" is used to reference this "Graphics" object. When you want to do
something with this object (which has been passed to the method as a
parameter) you refer to it as "g", and if you call methods in it, you
use g.methodname(parameters), as can be seen with "g.drawString..."
Whenever you declare a variable (like g) you need to write it's "type"
and then a name for it. (You refer to it with it's name). This is why in
the parameter section you see "Graphics g". Its declaring that there
will be a variable "g" which refers to an object/instance of type/class
"Graphics". In this case, the object is being passed to the method by
whatever called the method i.e object already exists, and doesn't need
to be created ("new").
Hope this isn't confusing.
Regards,
Ross..
--
*TO E-MAIL ME: Reverse the order of the domain name in my e-mail
address.*
Ross Vumbaca, a 'poor' Uni student at USyd.edu.au
http://www.fl.net.au/~rossv, e-mail: rossv@fl dot net dot au (fix this
if you e-mail me!)
Running on an Amiga 3000, NEC M700 17" thingy,
030/25, ECS, 8Mb Fast, 2Mb Chip, SCSI HDD's (never mind their size)
Kickstart 3.1 (40.68), OS 3.5, Linux 2.0 (RedHat 5.1) and an Opalvision
card -
("Designed in Australia", and keeping the Zorro bus populated).
--
Technical Details
Message-ID:
<38FFD29D.F0550C8E@au.net.fl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<JfBL4.425$v85.2035@news-server.bigpond.net.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,a6c6328d2bd0994c X-Google-Attributes: gid10d6db,public From: Ross Vumbaca <rossv@au.net.fl> Subject: Re: New to Java Date: 2000/04/21 Message-ID: <38FFD29D.F0550C8E@au.net.fl> X-Deja-AN: 613827054 Content-Transfer-Encoding: 7bit References: <JfBL4.425$v85.2035@news-server.bigpond.net.au> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Trace: 21 Apr 2000 14:01:31 +1000, a6-p17.syd.fl.net.au Organization: Customer of First Link Internet Services, Sydney, Australia MIME-Version: 1.0 Newsgroups: aus.computers.java