package concurrency.diners; import java.awt.*; class PhilCanvas extends Canvas { Diners controller; static final int NUMPHILS = 5; static final int THINKING = 0; static final int HUNGRY = 1; static final int GOTRIGHT = 2; static final int EATING =3; static final int GOTLEFT = 4; Image[] imgs = new Image[5]; double [] philX = new double[NUMPHILS]; double [] philY = new double[NUMPHILS]; int [] state = new int [NUMPHILS]; boolean[] redraw = new boolean[NUMPHILS]; double [] chopX = new double[NUMPHILS]; double [] chopY = new double[NUMPHILS]; boolean[] untable= new boolean[NUMPHILS]; boolean wasdeadlocked = false; boolean frozen = false; PhilCanvas(Diners controller) { super(); this.controller = controller; MediaTracker mt; mt = new MediaTracker(this); imgs[0] = controller.getImage(controller.getDocumentBase(), "image/thinking.gif"); mt.addImage(imgs[0], 0); imgs[1] = controller.getImage(controller.getDocumentBase(), "image/hungry.gif"); mt.addImage(imgs[1], 1); imgs[2] = controller.getImage(controller.getDocumentBase(), "image/gotright.gif"); mt.addImage(imgs[2], 2); imgs[3] = controller.getImage(controller.getDocumentBase(), "image/eating.gif"); mt.addImage(imgs[3], 3); imgs[4] = controller.getImage(controller.getDocumentBase(), "image/gotleft.gif"); mt.addImage(imgs[4], 4); try { mt.waitForID(0); mt.waitForID(1); mt.waitForID(2); mt.waitForID(3); mt.waitForID(4); } catch (java.lang.InterruptedException e) { System.out.println("Couldn't load one of the images"); } initPlacing(); } Image offscreen; Dimension offscreensize; Graphics offgraphics; void backdrop() { Dimension d = size(); if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offgraphics = offscreen.getGraphics(); offgraphics.setFont(new Font("Helvetica",Font.BOLD,18)); } offgraphics.setColor(Color.lightGray); offgraphics.fillRect(0, 0, size().width, size().height); for (int i = 0; i < NUMPHILS; i++) { redraw[i] = true; } } void drawtable() { offgraphics.setColor(Color.red); offgraphics.fillOval(105,105,90,90); offgraphics.setColor(Color.black); for(int i=0; i