FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Classes
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Classes  (Read 315 times)
beachmeat

WWW
Classes
« on: Jul 21st, 2003, 1:56am »

Hello everybody.
Im new to processing as well as to Java.
First of all many thanks for Processing, I think I will have some fun with it
Now the Qs
How do I construct a Class in Java/Processing?
How do I refer to this -> value?
 
example not working:
class Foo
{
  private char test;
  Foo(char test)
  {
    this->test=test;
 
    output()
    {
 print this->test;
    }
 
  }
}
 
inst = new Foo("Hello World");
inst->output();
 
How do I get this to work?
 
Bijeoma

myloveiloved
Re: Classes
« Reply #1 on: Jul 21st, 2003, 2:29am »

hello.  
heres a correct version with explanations along the way.
 
class Foo {
   
  //hello world is a sting not a char. a char is a   single character
  string test;
 
  Foo(sting test) {
    this.test = test;
  }
   
  void output() {
    print(test);
  }
}
 
//syntax for instantiating a class
//classname objectname = new classname();
Foo inst = new Foo("Hello World");
 
//syntax for refering to a method in an object of a class;
//objectname.methodname();
inst.output();
 
hope that explains everything.
 
Bijeoma

myloveiloved
Re: Classes
« Reply #2 on: Jul 21st, 2003, 2:31am »

class Foo {  
   
  String test;  
 
  Foo(String test) {  
    this.test = test;  
  }  
   
  void output() {  
    print(test);  
  }  
}  
 
Foo inst = new Foo("Hello World");  
inst.output();
 
beachmeat

WWW
Re: Classes
« Reply #3 on: Jul 21st, 2003, 4:13am »

Thanks very much.
I was mixed up with char vs. string because processing didnt highlight "string" - that was because string is Composite data, which I didnt know has to be constructed differently.
Things clearer, thanks again.
One more Q, how do i use "loop" in a class instance?
Manuel
« Last Edit: Jul 21st, 2003, 4:16am by beachmeat »  
Bijeoma

myloveiloved
Re: Classes
« Reply #4 on: Jul 21st, 2003, 4:26am »

im not sure why youd want to do that. you can use a for or while loop to create loops in a class or method. the the reserved loop method
 
the loop() function is read until the program is stopped. each statement within loop is read in sequence and after the last line is read, the first line is read again.
 
thats in the learning section under setup and loop.
 
 
benelek

35160983516098 WWW Email
Re: Classes
« Reply #5 on: Jul 21st, 2003, 7:56am »

Manuel, do you mean a seperate loop() type-thing within your class? (as seperate to the global loop() in p5)
 
arielm

WWW
Re: Classes
« Reply #6 on: Jul 21st, 2003, 9:39am »

maybe beachmeat means something like:
 
Code:

Sprite instance;
 
void setup()
{
  instance = new Sprite();
}
 
void loop()
{
  instance.loop();
}
 
class Sprite
{
  void loop()
  {
    println("foo");
  }
}

private note to benelek: hey, i'm not planning to enter any code contest this time
« Last Edit: Jul 21st, 2003, 9:43am by arielm »  

Ariel Malka | www.chronotext.org
benelek

35160983516098 WWW Email
Re: Classes
« Reply #7 on: Jul 21st, 2003, 12:33pm »

hehe, ur sure? bcos i reckon i could define a custom class in less lines than u
 
beachmeat

WWW
Re: Classes
« Reply #8 on: Jul 21st, 2003, 2:43pm »

Thanks to you all, the last example was the one i needed.
 
I want to make multiple instances that have their own loops - events that occur continously.
Just for the knowledge- is there any other way than with loop?
Like in Actionscript "onEnterFrame" or "setInterval" ?
 
arielm

WWW
Re: Classes
« Reply #9 on: Jul 21st, 2003, 3:35pm »

in the previous example of code, you coud just add in setup(), something like framerate(20)...
 
it will ensure that loop() is not called more than 20 times per seconds (for the other direction, it depends on what you process and what is your computer's speed...)
 
benelek, flight404 has already found the best method for extreme short coding: going to sleep and waiting for the perfect code to come in a dream (we still need a way to figure out how to remember things after we wake up!)
 

Ariel Malka | www.chronotext.org
benelek

35160983516098 WWW Email
Re: Classes
« Reply #10 on: Jul 21st, 2003, 4:38pm »

i don't know arilem, i find it scary when i'm trying to get to sleep and i can't stop thinking about code. lil' green code, with pointy ears and beady eyes...
 
Pages: 1 

« Previous topic | Next topic »