Thread View: aus.computers.java
4 messages
4 total messages
Started by David Belavy
Thu, 20 Apr 2000 00:00
New to Java
Author: David Belavy
Date: Thu, 20 Apr 2000 00:00
Date: Thu, 20 Apr 2000 00:00
16 lines
945 bytes
945 bytes
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?
Thanks,
David
Re: New to Java
Author: Alan
Date: Thu, 20 Apr 2000 00:00
Date: Thu, 20 Apr 2000 00:00
42 lines
1454 bytes
1454 bytes
g is a variable name, so the method called "paint" is called from another
program
by passing another "Graphics" type
eg
Graphics myG = new Graphics();
paint(myG);
could be a possible way of calling this method the "g" within the method has
a drawString method as g is of type Graphics
eg
Graphics.drawString(jav.util.Stirng, int,int)
exists.
Alan
"David Belavy" <dbelavy@mail.com> wrote in message
news:JfBL4.425$v85.2035@news-server.bigpond.net.au...
> 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?
>
> Thanks,
>
> David
>
>
Re: New to Java
Author: 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).
--
Re: New to Java
Author: Mad Dog
Date: Wed, 03 May 2000 00:00
Date: Wed, 03 May 2000 00:00
50 lines
1978 bytes
1978 bytes
g is the instance of an object of type Graphics
for example
if i declare
String myString = "cool";
i have just created an attribute of type String.
with that attribute comes all sorts of methods i can call because of
this fact.
eg
myString.charAt(2); // returns 'o'
this is because the class String has this method, and myString is of
type String.
so it is a similar thing with g
paint is passed a parramater of type Grapgics, you can then access all
those cool methods that come with an attribute of type g such as
drawString().
did that help?
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?
>
> Thanks,
>
> David
--
|\
____|@\
____/0 \
/ \
<----- \
\______ \
\=#=#=#=#=\_____________________________
| |\
| Final year Bach Applied Science (CS)|\\
| RMIT University Bundoora | \\
\ mail to: maddog100@rocketmail.com | \\
\_____________________________________| \)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads