We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all. I asked about using abstract classes yesterday here, but I think I have to go back and get the hang of something simpler first. (It's killing me! because I've read so much about this that it feels like I should know it all already!) So I'm trying to make a button class with the basic button characteristics, and make particular subclasses with different functionality.
here's what I've got so far: A main class called ButtonLinker:
void setup() {
size(960, 600);
line(120);
stroke(3);
}
FirstButton firstBtn = new FirstButton();
void draw() {
firstBtn.showBtn();
}
a class called Button:
class Button {
int xPos;
int yPos;
int lth ;
int wth;
}
and another class called FirstButton:
class FirstButton extends Button {
{
xPos = 300;
yPos = 300;
lth = 50;
wth = 50;
}
void showBtn() {
rect(xPos, yPos, lth, wth);
}
}
anyone see what's wrong?
Answers
Your FirstButton class doesn't have a constructor. You need to change line 4 to:
Thank you both. I'm sorry, I should have said I'm working on a processing.js project using Processing 2.2.1. The code above works for the java version, but not for the javascript version.
/*I just copy-pasted my own code above into a new sketch, and control-T'd it. Then commented out the dud line
line(120);
and it ran in the _java_ version. So I can't be a million miles away. Any thoughts on what's stopping it from running as .js? */JS Mode (PJS) can't transpile all Java features to JS.
There are 2 things in my sample that JS Mode fails at:
@Override
& Initialization block inside a class.W/ just some tiny adjustments it works for PJS too: :bz
http://ProcessingJS.org/tools/processing-helper.html
That works. I'll experiment with it.
Thanks very much!