Your question is marked ‘homework’ so according to forum rules we cannot give you a “full code” solution.
The following is the approach that I would use:
- Delete “public”; not necessary.
- Change name of test class to class Test extends PApplet.
- Inside of class Test create a Test() function.
- Inside of Test() add the following:
PApplet.runSketch(new String[]{this.getClass().getName()}, this);
surface.setTitle("PApplet");
String imgPath = "Users/yourName/Documents/Processing/sketchFolderName/data/logo.png";
img = loadImage(imgPath); // 加载图片
if (img == null) {
println("图片加载失败!");
}
- Add a settings() function to your Test class:
void settings() {
size(400, 400, P2D);
}
- Inside of draw() call the image: image(img,0,0)
- Delete the ‘main’ function and replace it with a separate setup() function outside of the Test class.
- Inside of the separate setup() call the new Test() like this: Test test = new Test();
- Inside of the separate setup() use surface.setVisible(false); if you don’t want to see the default Processing window.
I know it’s a lot, but I hope it helps you.
Addendum:
The question title suggests that you are interested in surface.setIcon(). If that is the case, and you are using the Windows operating system the following reference may be helpful: