Java处理在使用线程时不显示内容

Java处理在使用线程时不显示内容,java,processing,Java,Processing,我正在尝试使用处理API实现“哲学家进餐”。 我把代码组织成不同的类, 哲学家和监视器处理线程(我使用wait()和notify()。 食物、叉子和窗口来处理图形 我的代码如下: 监控类 public class Monitor implements MonitorInterface { Philosopher[] p; public Monitor(Philosopher[] p) { this.p = p; } @Override

我正在尝试使用处理API实现“哲学家进餐”。 我把代码组织成不同的类, 哲学家监视器处理线程(我使用wait()和notify()。 食物叉子窗口来处理图形

我的代码如下:

监控类

    public class Monitor implements MonitorInterface {
    Philosopher[] p;

    public Monitor(Philosopher[] p) {
        this.p = p;
    }

    @Override
    public synchronized void test_to_eat(int philosopher_position) {
        if (p[philosopher_position].status == PhilosopherStatus.STARVING
            && p[(philosopher_position + 1) % p.length].status != PhilosopherStatus.EATING
            && p[(philosopher_position - 1 + p.length) % p.length].status != PhilosopherStatus.EATING) {
            p[philosopher_position].status = PhilosopherStatus.EATING;
            notify();
        }
    }

    @Override
    public synchronized void take_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.STARVING;
        test_to_eat(philosopher_position);

        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public synchronized void put_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.THINKING;
        test_to_eat((philosopher_position + 1) % p.length);
        test_to_eat((philosopher_position - 1 + p.length) % p.length);
    }

    @Override
    public void eat() {
        System.out.println(Thread.currentThread().getName() + " ...EATING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void think() {
        System.out.println(Thread.currentThread().getName() + " ...THINKING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Philosopher extends Thread {
    private String name;
    PhilosopherStatus status;
    private Monitor m;
    private int position;
    private float pos_x, pos_y;
    PApplet p;

    public Philosopher(PApplet p, int position, String name, Monitor m, float pos_x, float pos_y) {
        this.position = position;
        this.name = name;
        this.m = m;
        this.pos_x = pos_x;
        this.pos_y = pos_y;
        this.p = p;
        this.status = PhilosopherStatus.THINKING;
        this.start();
    }

    public void show() {
            if (this.status.equals(PhilosopherStatus.THINKING)) {
                p.fill(20,28,255);
            } else if (this.status.equals(PhilosopherStatus.STARVING)) {
                p.fill(255,8,57);
            } else if (this.status.equals(PhilosopherStatus.EATING)) {
                p.fill(23,255,38);
            } else {
                p.fill(0);
            }

            p.rect(pos_x, pos_y, 45, 45);

            p.fill(0);
            p.textSize(15);
            p.textAlign(p.LEFT, p.LEFT); // centre le texte horizontalement et verticalement
            p.text(this.name, pos_x, pos_y + 50, 100, 200);

    }


    @Override
    public void run() {
        //while (true) {
            m.think();
            m.test_to_eat(this.position);
            m.take_fork(this.position);
            m.eat();
            m.put_fork(this.position);
        //}
    }

    public String getNamee() {
        return name;
    }

    public void setNamee(String name) {
        this.name = name;
    }

    public PhilosopherStatus getStatus() {
        return status;
    }

    public void setStatus(PhilosopherStatus status) {
        this.status = status;
    }


    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public float getPos_x() {
        return pos_x;
    }

    public void setPos_x(float pos_x) {
        this.pos_x = pos_x;
    }

    public float getPos_y() {
        return pos_y;
    }

    public void setPos_y(float pos_y) {
        this.pos_y = pos_y;
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Window extends PApplet{
    @Override

    public void settings() {
        size(800, 600);
        noLoop();
    }
    public void setup() {
        super.setup();
    }

    public void drawPhilosopher(Philosopher p) {
        PhilosopherStatus status = p.getStatus();
        float pos_x = p.getPos_x();
        float pos_y = p.getPos_y();
        String name = p.getNamee();

        if (status == PhilosopherStatus.THINKING)
            fill(20,28,255);
        else if (status == PhilosopherStatus.STARVING)
            fill(255,8,57);
        else if (status == PhilosopherStatus.EATING)
            fill(23,255,38);
        else
            fill(0);

        rect(pos_x, pos_y, 45, 45);

        fill(0);
        textSize(15);
        textAlign(LEFT, LEFT);
        text(name, pos_x, pos_y + 50, 100, 200);
    }

    @Override
    public void draw() {

        try {
            background(255);

            // Loading shapes
            PShape pasta = loadShape("./img/pasta.svg");
            PShape fork = loadShape("./img/fork.svg");

            // drawing shapes
            Food food = new Food(pasta, this);
            Fork f1 = new Fork(this, fork, 270, 360, 0, false);
            f1.show();

            Fork f2 = new Fork(this, fork, 340, 210, (float) 1.5, true);
            f2.show();

            Fork f3 = new Fork(this, fork, 560, 260, (float) 1.8, true);
            f3.show();

            Fork f4 = new Fork(this, fork, 545, 405, (float) 1.17, false);
            f4.show();

            Fork f5 = new Fork(this, fork, width/2 - 10, 450, 1, true);
            f5.show();

            // Drawing Philosophers
            Philosopher[] p = new Philosopher[5];
            Monitor m = new Monitor(p);

            p[0] = new Philosopher(this, 0, "A", m, width/2 - 25, 150);
            p[0].setName("A");


            p[1] = new Philosopher(this, 1, "B", m, width/2 + 130,  250);
            p[1].setName("B");

            p[2] = new Philosopher(this, 2, "C", m, width/2 + 70,  390);
            p[2].setName("C");

            p[3] = new Philosopher(this, 3, "D", m, width/2 - 120,  390);
            p[3].setName("D");

            p[4] = new Philosopher(this, 4, "E", m, width/2 - 170,  250);
            p[4].setName("E");

            for (Philosopher philo: p) {
                philo.show();
            }

            delay(3000);

            for (Philosopher philo: p) {
                philo.run();
            }

            try {
                p[0].join();
                p[1].join();
                p[2].join();
                p[3].join();
                p[4].join();
            } catch (InterruptedException e) {
               e.printStackTrace();
            }



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
import processing.core.PApplet;

public class Main extends PApplet {

    public static void main(String[] args) {
        Window w = new Window();

        PApplet.main(Window.class.getName());
    }
}
哲学家班

    public class Monitor implements MonitorInterface {
    Philosopher[] p;

    public Monitor(Philosopher[] p) {
        this.p = p;
    }

    @Override
    public synchronized void test_to_eat(int philosopher_position) {
        if (p[philosopher_position].status == PhilosopherStatus.STARVING
            && p[(philosopher_position + 1) % p.length].status != PhilosopherStatus.EATING
            && p[(philosopher_position - 1 + p.length) % p.length].status != PhilosopherStatus.EATING) {
            p[philosopher_position].status = PhilosopherStatus.EATING;
            notify();
        }
    }

    @Override
    public synchronized void take_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.STARVING;
        test_to_eat(philosopher_position);

        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public synchronized void put_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.THINKING;
        test_to_eat((philosopher_position + 1) % p.length);
        test_to_eat((philosopher_position - 1 + p.length) % p.length);
    }

    @Override
    public void eat() {
        System.out.println(Thread.currentThread().getName() + " ...EATING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void think() {
        System.out.println(Thread.currentThread().getName() + " ...THINKING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Philosopher extends Thread {
    private String name;
    PhilosopherStatus status;
    private Monitor m;
    private int position;
    private float pos_x, pos_y;
    PApplet p;

    public Philosopher(PApplet p, int position, String name, Monitor m, float pos_x, float pos_y) {
        this.position = position;
        this.name = name;
        this.m = m;
        this.pos_x = pos_x;
        this.pos_y = pos_y;
        this.p = p;
        this.status = PhilosopherStatus.THINKING;
        this.start();
    }

    public void show() {
            if (this.status.equals(PhilosopherStatus.THINKING)) {
                p.fill(20,28,255);
            } else if (this.status.equals(PhilosopherStatus.STARVING)) {
                p.fill(255,8,57);
            } else if (this.status.equals(PhilosopherStatus.EATING)) {
                p.fill(23,255,38);
            } else {
                p.fill(0);
            }

            p.rect(pos_x, pos_y, 45, 45);

            p.fill(0);
            p.textSize(15);
            p.textAlign(p.LEFT, p.LEFT); // centre le texte horizontalement et verticalement
            p.text(this.name, pos_x, pos_y + 50, 100, 200);

    }


    @Override
    public void run() {
        //while (true) {
            m.think();
            m.test_to_eat(this.position);
            m.take_fork(this.position);
            m.eat();
            m.put_fork(this.position);
        //}
    }

    public String getNamee() {
        return name;
    }

    public void setNamee(String name) {
        this.name = name;
    }

    public PhilosopherStatus getStatus() {
        return status;
    }

    public void setStatus(PhilosopherStatus status) {
        this.status = status;
    }


    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public float getPos_x() {
        return pos_x;
    }

    public void setPos_x(float pos_x) {
        this.pos_x = pos_x;
    }

    public float getPos_y() {
        return pos_y;
    }

    public void setPos_y(float pos_y) {
        this.pos_y = pos_y;
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Window extends PApplet{
    @Override

    public void settings() {
        size(800, 600);
        noLoop();
    }
    public void setup() {
        super.setup();
    }

    public void drawPhilosopher(Philosopher p) {
        PhilosopherStatus status = p.getStatus();
        float pos_x = p.getPos_x();
        float pos_y = p.getPos_y();
        String name = p.getNamee();

        if (status == PhilosopherStatus.THINKING)
            fill(20,28,255);
        else if (status == PhilosopherStatus.STARVING)
            fill(255,8,57);
        else if (status == PhilosopherStatus.EATING)
            fill(23,255,38);
        else
            fill(0);

        rect(pos_x, pos_y, 45, 45);

        fill(0);
        textSize(15);
        textAlign(LEFT, LEFT);
        text(name, pos_x, pos_y + 50, 100, 200);
    }

    @Override
    public void draw() {

        try {
            background(255);

            // Loading shapes
            PShape pasta = loadShape("./img/pasta.svg");
            PShape fork = loadShape("./img/fork.svg");

            // drawing shapes
            Food food = new Food(pasta, this);
            Fork f1 = new Fork(this, fork, 270, 360, 0, false);
            f1.show();

            Fork f2 = new Fork(this, fork, 340, 210, (float) 1.5, true);
            f2.show();

            Fork f3 = new Fork(this, fork, 560, 260, (float) 1.8, true);
            f3.show();

            Fork f4 = new Fork(this, fork, 545, 405, (float) 1.17, false);
            f4.show();

            Fork f5 = new Fork(this, fork, width/2 - 10, 450, 1, true);
            f5.show();

            // Drawing Philosophers
            Philosopher[] p = new Philosopher[5];
            Monitor m = new Monitor(p);

            p[0] = new Philosopher(this, 0, "A", m, width/2 - 25, 150);
            p[0].setName("A");


            p[1] = new Philosopher(this, 1, "B", m, width/2 + 130,  250);
            p[1].setName("B");

            p[2] = new Philosopher(this, 2, "C", m, width/2 + 70,  390);
            p[2].setName("C");

            p[3] = new Philosopher(this, 3, "D", m, width/2 - 120,  390);
            p[3].setName("D");

            p[4] = new Philosopher(this, 4, "E", m, width/2 - 170,  250);
            p[4].setName("E");

            for (Philosopher philo: p) {
                philo.show();
            }

            delay(3000);

            for (Philosopher philo: p) {
                philo.run();
            }

            try {
                p[0].join();
                p[1].join();
                p[2].join();
                p[3].join();
                p[4].join();
            } catch (InterruptedException e) {
               e.printStackTrace();
            }



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
import processing.core.PApplet;

public class Main extends PApplet {

    public static void main(String[] args) {
        Window w = new Window();

        PApplet.main(Window.class.getName());
    }
}
窗口类

    public class Monitor implements MonitorInterface {
    Philosopher[] p;

    public Monitor(Philosopher[] p) {
        this.p = p;
    }

    @Override
    public synchronized void test_to_eat(int philosopher_position) {
        if (p[philosopher_position].status == PhilosopherStatus.STARVING
            && p[(philosopher_position + 1) % p.length].status != PhilosopherStatus.EATING
            && p[(philosopher_position - 1 + p.length) % p.length].status != PhilosopherStatus.EATING) {
            p[philosopher_position].status = PhilosopherStatus.EATING;
            notify();
        }
    }

    @Override
    public synchronized void take_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.STARVING;
        test_to_eat(philosopher_position);

        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public synchronized void put_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.THINKING;
        test_to_eat((philosopher_position + 1) % p.length);
        test_to_eat((philosopher_position - 1 + p.length) % p.length);
    }

    @Override
    public void eat() {
        System.out.println(Thread.currentThread().getName() + " ...EATING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void think() {
        System.out.println(Thread.currentThread().getName() + " ...THINKING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Philosopher extends Thread {
    private String name;
    PhilosopherStatus status;
    private Monitor m;
    private int position;
    private float pos_x, pos_y;
    PApplet p;

    public Philosopher(PApplet p, int position, String name, Monitor m, float pos_x, float pos_y) {
        this.position = position;
        this.name = name;
        this.m = m;
        this.pos_x = pos_x;
        this.pos_y = pos_y;
        this.p = p;
        this.status = PhilosopherStatus.THINKING;
        this.start();
    }

    public void show() {
            if (this.status.equals(PhilosopherStatus.THINKING)) {
                p.fill(20,28,255);
            } else if (this.status.equals(PhilosopherStatus.STARVING)) {
                p.fill(255,8,57);
            } else if (this.status.equals(PhilosopherStatus.EATING)) {
                p.fill(23,255,38);
            } else {
                p.fill(0);
            }

            p.rect(pos_x, pos_y, 45, 45);

            p.fill(0);
            p.textSize(15);
            p.textAlign(p.LEFT, p.LEFT); // centre le texte horizontalement et verticalement
            p.text(this.name, pos_x, pos_y + 50, 100, 200);

    }


    @Override
    public void run() {
        //while (true) {
            m.think();
            m.test_to_eat(this.position);
            m.take_fork(this.position);
            m.eat();
            m.put_fork(this.position);
        //}
    }

    public String getNamee() {
        return name;
    }

    public void setNamee(String name) {
        this.name = name;
    }

    public PhilosopherStatus getStatus() {
        return status;
    }

    public void setStatus(PhilosopherStatus status) {
        this.status = status;
    }


    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public float getPos_x() {
        return pos_x;
    }

    public void setPos_x(float pos_x) {
        this.pos_x = pos_x;
    }

    public float getPos_y() {
        return pos_y;
    }

    public void setPos_y(float pos_y) {
        this.pos_y = pos_y;
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Window extends PApplet{
    @Override

    public void settings() {
        size(800, 600);
        noLoop();
    }
    public void setup() {
        super.setup();
    }

    public void drawPhilosopher(Philosopher p) {
        PhilosopherStatus status = p.getStatus();
        float pos_x = p.getPos_x();
        float pos_y = p.getPos_y();
        String name = p.getNamee();

        if (status == PhilosopherStatus.THINKING)
            fill(20,28,255);
        else if (status == PhilosopherStatus.STARVING)
            fill(255,8,57);
        else if (status == PhilosopherStatus.EATING)
            fill(23,255,38);
        else
            fill(0);

        rect(pos_x, pos_y, 45, 45);

        fill(0);
        textSize(15);
        textAlign(LEFT, LEFT);
        text(name, pos_x, pos_y + 50, 100, 200);
    }

    @Override
    public void draw() {

        try {
            background(255);

            // Loading shapes
            PShape pasta = loadShape("./img/pasta.svg");
            PShape fork = loadShape("./img/fork.svg");

            // drawing shapes
            Food food = new Food(pasta, this);
            Fork f1 = new Fork(this, fork, 270, 360, 0, false);
            f1.show();

            Fork f2 = new Fork(this, fork, 340, 210, (float) 1.5, true);
            f2.show();

            Fork f3 = new Fork(this, fork, 560, 260, (float) 1.8, true);
            f3.show();

            Fork f4 = new Fork(this, fork, 545, 405, (float) 1.17, false);
            f4.show();

            Fork f5 = new Fork(this, fork, width/2 - 10, 450, 1, true);
            f5.show();

            // Drawing Philosophers
            Philosopher[] p = new Philosopher[5];
            Monitor m = new Monitor(p);

            p[0] = new Philosopher(this, 0, "A", m, width/2 - 25, 150);
            p[0].setName("A");


            p[1] = new Philosopher(this, 1, "B", m, width/2 + 130,  250);
            p[1].setName("B");

            p[2] = new Philosopher(this, 2, "C", m, width/2 + 70,  390);
            p[2].setName("C");

            p[3] = new Philosopher(this, 3, "D", m, width/2 - 120,  390);
            p[3].setName("D");

            p[4] = new Philosopher(this, 4, "E", m, width/2 - 170,  250);
            p[4].setName("E");

            for (Philosopher philo: p) {
                philo.show();
            }

            delay(3000);

            for (Philosopher philo: p) {
                philo.run();
            }

            try {
                p[0].join();
                p[1].join();
                p[2].join();
                p[3].join();
                p[4].join();
            } catch (InterruptedException e) {
               e.printStackTrace();
            }



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
import processing.core.PApplet;

public class Main extends PApplet {

    public static void main(String[] args) {
        Window w = new Window();

        PApplet.main(Window.class.getName());
    }
}
主类

    public class Monitor implements MonitorInterface {
    Philosopher[] p;

    public Monitor(Philosopher[] p) {
        this.p = p;
    }

    @Override
    public synchronized void test_to_eat(int philosopher_position) {
        if (p[philosopher_position].status == PhilosopherStatus.STARVING
            && p[(philosopher_position + 1) % p.length].status != PhilosopherStatus.EATING
            && p[(philosopher_position - 1 + p.length) % p.length].status != PhilosopherStatus.EATING) {
            p[philosopher_position].status = PhilosopherStatus.EATING;
            notify();
        }
    }

    @Override
    public synchronized void take_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.STARVING;
        test_to_eat(philosopher_position);

        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public synchronized void put_fork(int philosopher_position) {
        p[philosopher_position].status = PhilosopherStatus.THINKING;
        test_to_eat((philosopher_position + 1) % p.length);
        test_to_eat((philosopher_position - 1 + p.length) % p.length);
    }

    @Override
    public void eat() {
        System.out.println(Thread.currentThread().getName() + " ...EATING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void think() {
        System.out.println(Thread.currentThread().getName() + " ...THINKING...");
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Philosopher extends Thread {
    private String name;
    PhilosopherStatus status;
    private Monitor m;
    private int position;
    private float pos_x, pos_y;
    PApplet p;

    public Philosopher(PApplet p, int position, String name, Monitor m, float pos_x, float pos_y) {
        this.position = position;
        this.name = name;
        this.m = m;
        this.pos_x = pos_x;
        this.pos_y = pos_y;
        this.p = p;
        this.status = PhilosopherStatus.THINKING;
        this.start();
    }

    public void show() {
            if (this.status.equals(PhilosopherStatus.THINKING)) {
                p.fill(20,28,255);
            } else if (this.status.equals(PhilosopherStatus.STARVING)) {
                p.fill(255,8,57);
            } else if (this.status.equals(PhilosopherStatus.EATING)) {
                p.fill(23,255,38);
            } else {
                p.fill(0);
            }

            p.rect(pos_x, pos_y, 45, 45);

            p.fill(0);
            p.textSize(15);
            p.textAlign(p.LEFT, p.LEFT); // centre le texte horizontalement et verticalement
            p.text(this.name, pos_x, pos_y + 50, 100, 200);

    }


    @Override
    public void run() {
        //while (true) {
            m.think();
            m.test_to_eat(this.position);
            m.take_fork(this.position);
            m.eat();
            m.put_fork(this.position);
        //}
    }

    public String getNamee() {
        return name;
    }

    public void setNamee(String name) {
        this.name = name;
    }

    public PhilosopherStatus getStatus() {
        return status;
    }

    public void setStatus(PhilosopherStatus status) {
        this.status = status;
    }


    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public float getPos_x() {
        return pos_x;
    }

    public void setPos_x(float pos_x) {
        this.pos_x = pos_x;
    }

    public float getPos_y() {
        return pos_y;
    }

    public void setPos_y(float pos_y) {
        this.pos_y = pos_y;
    }
}
import processing.core.PApplet;
import processing.core.PShape;

public class Window extends PApplet{
    @Override

    public void settings() {
        size(800, 600);
        noLoop();
    }
    public void setup() {
        super.setup();
    }

    public void drawPhilosopher(Philosopher p) {
        PhilosopherStatus status = p.getStatus();
        float pos_x = p.getPos_x();
        float pos_y = p.getPos_y();
        String name = p.getNamee();

        if (status == PhilosopherStatus.THINKING)
            fill(20,28,255);
        else if (status == PhilosopherStatus.STARVING)
            fill(255,8,57);
        else if (status == PhilosopherStatus.EATING)
            fill(23,255,38);
        else
            fill(0);

        rect(pos_x, pos_y, 45, 45);

        fill(0);
        textSize(15);
        textAlign(LEFT, LEFT);
        text(name, pos_x, pos_y + 50, 100, 200);
    }

    @Override
    public void draw() {

        try {
            background(255);

            // Loading shapes
            PShape pasta = loadShape("./img/pasta.svg");
            PShape fork = loadShape("./img/fork.svg");

            // drawing shapes
            Food food = new Food(pasta, this);
            Fork f1 = new Fork(this, fork, 270, 360, 0, false);
            f1.show();

            Fork f2 = new Fork(this, fork, 340, 210, (float) 1.5, true);
            f2.show();

            Fork f3 = new Fork(this, fork, 560, 260, (float) 1.8, true);
            f3.show();

            Fork f4 = new Fork(this, fork, 545, 405, (float) 1.17, false);
            f4.show();

            Fork f5 = new Fork(this, fork, width/2 - 10, 450, 1, true);
            f5.show();

            // Drawing Philosophers
            Philosopher[] p = new Philosopher[5];
            Monitor m = new Monitor(p);

            p[0] = new Philosopher(this, 0, "A", m, width/2 - 25, 150);
            p[0].setName("A");


            p[1] = new Philosopher(this, 1, "B", m, width/2 + 130,  250);
            p[1].setName("B");

            p[2] = new Philosopher(this, 2, "C", m, width/2 + 70,  390);
            p[2].setName("C");

            p[3] = new Philosopher(this, 3, "D", m, width/2 - 120,  390);
            p[3].setName("D");

            p[4] = new Philosopher(this, 4, "E", m, width/2 - 170,  250);
            p[4].setName("E");

            for (Philosopher philo: p) {
                philo.show();
            }

            delay(3000);

            for (Philosopher philo: p) {
                philo.run();
            }

            try {
                p[0].join();
                p[1].join();
                p[2].join();
                p[3].join();
                p[4].join();
            } catch (InterruptedException e) {
               e.printStackTrace();
            }



        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
import processing.core.PApplet;

public class Main extends PApplet {

    public static void main(String[] args) {
        Window w = new Window();

        PApplet.main(Window.class.getName());
    }
}
我将我的哲学家表示为正方形,我期望的行为是,每当哲学家的状态改变时,我的正方形将改变它的颜色

但我得到的只是一个空白屏幕

请注意,当使用控制台测试我的代码时,它运行正常,没有任何错误或奇怪的行为

先谢谢你