Home>

To control each display without delay,
I am trying to achieve this by creating multiple sub-threads with the same functionality.

And for this, add the function in the created class
An argument has been set. ↓
public void run (int now, int before, int gValue)
Then, the following error message occurred.

Error message
The method run (int, int, int) of type ○○○ .SubThread must override or implement a supertype method
The type ○○○ .SubThread must implement the inherited abstract method Runnable.run ()


Searching on the net , removing @Override There was,
The two error messages are not gone,

The type ○○○ .SubThread must implement the inherited abstract method Runnable.run ()


Remained.

Is there any way to avoid errors while keeping arguments in run ()?

Applicable source code
class SubThread implements Runnable {
  // execution permission FLG
  private boolean running = true;
  private boolean toggle = true;
  // this is executed
  @Override
    public void run (int now, int before, int gValue) {
    while (running) {
      switch (now) {
      case 0:
        case0 (before, gValue);
        break;
      case 1:
        case1 (before, gValue);
        break;
      case 2:
        case2 (before, gValue);
        break;
      }
      // update value
      before = now;
      switch (now) {
      case 0:
        trySleep (0.01);
        break;
      case 1:
        trySleep (0.5);
        break;
      case 2:
        trySleep (0.01);
        break;
      }
    }
    println ("Sub Thread exit");
  }
  void case0 (int Before, int G) {
    if (Before == 0) {
      if (G + 4<255) {
        G = G + 4;
        println (G);
      } else {
        G = 255;
      }
    } else if (Before == 1) {
      G = 255;
    } else if (Before == 2) {
      G = 0;
    }
    println ("state | 0");
  }
  void case1 (int Before, int G) {
    if (toggle) {
      G = 0;
    } else {
      G = 255;
    }
    // flag inversion
    toggle =! toggle;
    println (Before);
    println ("state | 1");
  }
  void case2 (int Before, int G) {
    if (Before == 2) {
      if (G-4>0) {
        G = G-4;
        println (G);
      } else {
        G = 0;
      }
    } else if (Before == 1) {
      G = 255;
    }
    println ("state | 2");
  }
  void trySleep (float time) {
    try {
      Thread.sleep ((long) (time * 1000));
    }
    catch (InterruptedException ex) {
      ex.printStackTrace ();
    }
  }
}

The code was imitated and the following code was used as a reference.

http://mslabo.sakura.ne.jp/WordPress/make/processing Reverse lookup reference/To implement multi-threading/

Supplemental information (FW/tool version etc.)

processing 3.4

  • Answer # 1

    As long as

    @Overrideis declared, the method must override the parent class or the implemented interface method.
    The implemented Runnable interface has arun ()method with no arguments, but norun (int, int, int)with arguments.
    In other words, a compile error occurs because the override condition is not satisfied.

    If

    @Overrideis removed, the above reason disappears, so the compile error disappears, but as long as the Runnable interface is implemented, therun ()method with no arguments Is obliged to implement. Since this obligation is not fulfilled, it still results in a compilation error.

    In the end, it is impossible to start from arun (int, int, int)method with an argument. You can only call another method fromrun ()without an argument.