令牌语法错误 "class",需要标识符

Syntax error on token "class", Identifier expected

我的 Processing 程序有 2 个选项卡。我实际上从 YouTube 教程中复制并粘贴了确切的代码,并且在 运行.

时不断收到错误消息

选项卡 1:

class Bubble {    

float x;
float y;

Bubble (){
  x=width/2;
  y=height; 
}

void ascend (){
  y--;
}

void display() {
  stroke(0);
  fill(127); 
  ellipse(x,y,64,64); 
  }      
}

选项卡 2:


Bubble b; 

void setup() {
  size(640,360); 
  b=new Bubble();
}

void draw () {
  background(255); 
  b.ascend();
  b.display();
  //b.top();
}

错误消息说:

Syntax error on token "class", Identifier expected

setup()draw() 等处理函数需要在第一个选项卡中。

我不太确定这是为什么。这不是绝对必要的,因为所有选项卡都会转换为一个 Java 文件,除非您的选项卡名称以 .java 结尾。我猜这是 Processing -> Java 编译器的一个怪癖。

您可以在 Processing GitHub repo 上提交错误,但我认为最好的办法是确保所有处理功能都在第一个选项卡中。