Solved: Question about setting a value for x

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

OneLuv

Thread Starter
Joined
Dec 28, 2006
Messages
274
Part of the assignment said set the x and y values of start to 10. The code looked like:

start.x = 10;
start.y = 10;

Can someone tell me why the start (dot) x ? I see in other parts of the code so far I have encountered g (dot)drawString.

Or point me in the right direction to find out why. I can't remember to do somethings if I don't know why they are done.

Thanks much:)
 
Joined
Apr 30, 2001
Messages
2,636
SomeClass.java
Code:
public class SomeClass {
    public int x; // public member attribute
    public int y; // public member attribute
}
TestProgram.java
Code:
public class TestProgram {
    public static void main(String[] args) {
        SomeClass start = new SomeClass(); // create an instance 'start' of SomeClass
        start.x = 44; // Set start's public x member (which is an int) to 44
        start.y = 33;
        System.out.println(start.x);
        System.out.println(start.y);
    }
}
In the case of g.drawString(), g is an instance of the Graphics class and drawString is a member function of the Graphics class. Since you're dealing with the g instance, if you want to call drawString for g, you do g.drawString("string", 5, 5) for example.

Is that what you mean?
 
Joined
Jun 29, 2007
Messages
78
Learn all about classes.
Don't worry, it's a very simple concept, you'll get it.
The . is how you access members of a class.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top