Forums Register Login

A simple problem

+Pie Number of slices to send: Send
I'm getting a coding problem that is quite simple to fix, I just can't figure out why it isn't working. I'm simplifying code to make it easier to read and to exclude the stuff that doesn't matter right now. I have two classes. One is GUIView, which has the method as follows:



The other class (Model) is trying to call the value of int size by using the following method.



The error is on size. "Size cannot be resolved to a variable"
+Pie Number of slices to send: Send
set the setter and getter methods for the first class;
if both he class are in same package you will be able to access the variable by Object of the class, usually by getSize() function written.

refer the class below.

Class One
{
private int size=0;
public void setBoardSize(int s)
{
this.size=s;
}

public int getSize()
{
return this.size;
}
+Pie Number of slices to send: Send
Thanks, that worked perfectly.
+Pie Number of slices to send: Send
Atul Darne, please remember correct indentation and the code button.
+Pie Number of slices to send: Send
And to the original poster, please do not name "getter" methods, that is, methods that only return the value of an attribute, with "set" prefix. It will make your code really confusing.

So instead of:


Do:


Mathieu
http://simpleadn.blogspot.com
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 642 times.
Similar Threads
Need some help, pleeaaase!!
negative color
Class relations mess - OOP
OOP Modeling - Separate GUI from implementaion-How to refer to class where have more than one method
Confused on how to create a rectangle
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:10:13.