arraylist as a function parameter?
in
Programming Questions
•
8 months ago
hello!
I just try to use an arraylist as a function parameter
Possible?
I receive an error in line 12 not a known constr lalala....
see bold part!
The idea is I want to create several local menues and since each of them can have different number of lines, each has an arraylist of lines..........
Or do I have to define a type ArrayList<LineInTheLocalMenu> ? How?
Thanks!
Greetings, Chrisir
- //
- ArrayList<LocalMenu> menus = new ArrayList();
- void setup()
- {
- size( 800, 800 );
- //
- ArrayList<LineInTheLocalMenu> lines = new ArrayList();
- lines.clear();
- lines.add( new LineInTheLocalMenu ( "Command 1 ", "This is command one, see?" ));
- lines.add( new LineInTheLocalMenu ( "Command 2 ", "This is command TWO, see?" ));
- lines.add( new LineInTheLocalMenu ( "Another cunning Command ", "This is command 3." ));
- LocalMenu test1 = new LocalMenu(333.0, 333.0, "Menu for Circle", "Wow.", lines);
- // ----
- menus.add( test1 );
- menus.add(new LocalMenu(93, 233, "2222", "foll"));
- menus.add(new LocalMenu(153, 173, "23", "roll"));
- //
- } // setup
- void draw()
- {
- background(0);
- for (int j = 0; j< menus.size(); j++) {
- LocalMenu myMapPoint = mapPoints.get(j);
- myMapPoint.display();
- } // for
- for (int j = 0; j< menus.size(); j++) {
- LocalMenu myMapPoint = mapPoints.get(j);
- if (myMapPoint.mouseOver())
- break;
- } // for
- } // draw
- // =====================================
- class LocalMenu {
- PVector pos = new PVector();
- String name;
- String textMouseOver;
- ArrayList<LineInTheLocalMenu> lines = new ArrayList();
- // constr
- localMenu ( /// MUST BE big L // edited
- float x_, float y_,
- String name_,
- String textMouseOver_,
- ArrayList<LineInTheLocalMenu> lines_ ) { // ArrayList<LineInTheLocalMenu> lines_ ????
- pos.x=x_;
- pos.y=y_;
- name=name_;
- textMouseOver=textMouseOver_;
- lines=lines_;
- }// constr
- void display() {
- fill(245);
- text(name, pos.x, pos.y);
- int i=0;
- for (LineInTheLocalMenu oneLine : lines ) {
- text(line.content, pos.x+5, y+10*i);
- }
- } // method
- boolean mouseOver() {
- if (dist(pos.x, pos.y, mouseX, mouseY) < 50 ) {
- noFill();
- stroke(245);
- rect(pos.x+12, pos.y+12, 40, 40);
- fill(255);
- text(textMouseOver, pos.x+12+4, pos.y+12+4, 40, 40);
- return true;
- }
- return false;
- } // method
- } //
- // ===============================================================
- class LineInTheLocalMenu {
- // PVector pos = new PVector();
- String content;
- String textMouseOver;
- // constr
- LineInTheLocalMenu ( String content_, String textMouseOver_ ) {
- content=content_;
- textMouseOver=textMouseOver_;
- }// constr
- void display() {
- fill(245);
- text(name, pos.x, pos.y);
- } // method
- boolean mouseOver() {
- if (dist(pos.x, pos.y, mouseX, mouseY) < 50 ) {
- noFill();
- stroke(245);
- rect(pos.x+12, pos.y+12, 40, 40);
- fill(255);
- text(textMouseOver, pos.x+12+4, pos.y+12+4, 40, 40);
- return true;
- }
- return false;
- } // method
- }
- // ===============================================================
1