Help on POO

Joined
Dec 23, 2011
Messages
1,906
Reaction score
2,531
i'm transfering my Domain2 Editor Tool ( perfect world ) to OO, but i can't use variables from the object why ?
on Netbeans IDE, he say cannot find symbol, Symbol: timestamp class, <identifier> expect


Domain2.java
Code:
package com.company.Structure;
public class Domain2 {
    
        public int timestamp;
	public float unknown1;

	public int zones_count;

	public Zones[] zones;

	public int battletime_count;

	public BattleTime[] battletime;

	public int timemax;
        
        public Domain2(){
        }
}

LoadClient.java
Code:
package com.company.Structure;
import com.company.Utils.BinaryReader;
import com.company.Utils.BinaryWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class LoadClient {
    
    public Domain2 domain;
    public Domain2 values;
    int i;
    int j;
    
    public LoadClient(BinaryReader br) throws IOException {
        this.domain = new Domain2() {
            		timestamp = br.ReadInt32();
			unknown1 = br.ReadSingle();
			zones_count = br.ReadInt32();
			zones = new Zones[this.domain2.zones_count];
        };
        
    }
    
}
 
Last edited:
If you use "new Domain2(){}, you create an array of Domain2, where in your example timestamp is not an object of type Domain2.
PHP:
Domain2  domain1 = new Domain2();
Domain2  domain2 = new Domain2();
Domain2  domain3 = new Domain2();
Domain2 myDomain[]= new Domain2() {domain1, domain2, domain3, etc};

The proper use to create and initialize Domain2 is:
PHP:
this.domain = new Domain2();
this.domain.timestamp = br.ReadInt32();
this.domain.unknown1 = br.ReadSingle();
this.domain.zones_count = br.ReadInt32();
this.domain.zones = new Zones[this.domain2.zones_count];
 
You were trying to set properties in the instantiation that is only possible in C#, but those fields are not even properties, and properties do not exist in Java.
 
Use a constructor like:

Code:
public class MyClass
{

private int width;
private int height;

public MyClass(int width, int height)
{
this.width = width;
this.height = height;
}

public int getWidth()
{
return width;
}
}

and then you can instantiate it like:

Code:
MyClass someObject = new MyClass(10, 50);

System.out.println(someObject.getWidth()); //Prints 10
Is anyone else enjoying the fact this thread uses the term 'POO' instead of 'OOP'? Lol, I love it! It should have been called POO from the beginning.

OOP object oriented programming.
functional programming isn't called PF. It makes no sense. OOP is the correct name for it.
 
Is anyone else enjoying the fact this thread uses the term 'POO' instead of 'OOP'? Lol, I love it! It should have been called POO from the beginning.

In my language is called POO(Programare Orientata pe Obiecte) which is Translated version of OOP.

Since the OP is from Brazil, in Portuguese is Programação Orientada a Objetos(used google translate)
 
Is anyone else enjoying the fact this thread uses the term 'POO' instead of 'OOP'? Lol, I love it! It should have been called POO from the beginning.
And you just called object oriented programming literally **** ...

functional programming isn't called PF. It makes no sense. OOP is the correct name for it.
It's rather called PP (procedural programming) and yes, it sounds like "pee pee". So the chapter is closed, I guess.
 
sorry not updated thread
my code now works fine

Code:
public class LoadClient {

    public Domain2 domain;
    int i;
    int j;

    public LoadClient(BinaryReader br) throws IOException {
        this.domain = new Domain2();
        this.domain.timestamp = br.ReadInt32();
        this.domain.unknown1 = br.ReadSingle();
 
Back