いつもお世話になっています。
前提・実現したいこと
遅滞なく各表示をコントロールするために、
同じ機能を有する複数のサブスレッドを立ててこれを達成しようとしています。
そしてこのために、作成したクラスの中の関数に
引数を設定しました。↓
public void run(int now, int before, int gValue)
すると、以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
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()
ネットで検索すると、@Overrideを削除すると解決するとありましたが、
2つのエラーメッセージが消えた訳ではなく、
The type ○○○.SubThread must implement the inherited abstract method Runnable.run()
が残ったままでした。
run()に引数を持たせたまま、エラーを回避する方法はないでしょうか。
該当のソースコード
processing
1class SubThread implements Runnable { 2 // 実行許可FLG 3 private boolean running = true; 4 5 private boolean toggle = true; 6 7 // ここが実行される 8 @Override 9 public void run(int now, int before, int gValue) { 10 11 while (running) { 12 switch(now) { 13 case 0: 14 case0(before, gValue); 15 break; 16 17 case 1: 18 case1(before, gValue); 19 break; 20 21 case 2: 22 case2(before, gValue); 23 break; 24 } 25 26 // 値を更新 27 before = now; 28 29 switch (now) { 30 case 0: 31 trySleep(0.01); 32 break; 33 34 case 1: 35 trySleep(0.5); 36 break; 37 38 case 2: 39 trySleep(0.01); 40 break; 41 } 42 } 43 println("Sub Thread exit"); 44 } 45 46 void case0(int Before, int G) { 47 48 if (Before == 0) { 49 50 if (G + 4 < 255) { 51 52 G = G + 4; 53 println(G); 54 } else { 55 56 G = 255; 57 } 58 } else if (Before == 1) { 59 G = 255; 60 } else if (Before == 2) { 61 G = 0; 62 } 63 println("state|0"); 64 } 65 66 void case1(int Before, int G) { 67 68 if (toggle) { 69 G = 0; 70 } else { 71 G = 255; 72 } 73 // フラグ反転 74 toggle = !toggle; 75 println(Before); 76 println("state|1"); 77 } 78 79 void case2(int Before, int G) { 80 81 if (Before == 2) { 82 83 if (G - 4 > 0) { 84 G = G - 4; 85 println(G); 86 } else { 87 G = 0; 88 } 89 } else if (Before == 1) { 90 G = 255; 91 } 92 println("state|2"); 93 } 94 95 void trySleep(float time) { 96 try { 97 Thread.sleep((long)(time * 1000)); 98 } 99 catch (InterruptedException ex) { 100 ex.printStackTrace(); 101 } 102 } 103}
試したこと
コードは見様見真似で下記のコードを参考にしました。
http://mslabo.sakura.ne.jp/WordPress/make/processing 逆引きリファレンス/マルチスレッドを実現するには/
補足情報(FW/ツールのバージョンなど)
processing 3.4
回答1件
あなたの回答
tips
プレビュー