1 31 package org.objectweb.proactive.examples.readers; 32 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 36 public class ReadCanvas extends javax.swing.JPanel { 37 38 private int[] readers; 39 private int[] writers; 40 41 42 public ReadCanvas() { 43 readers = new int[3]; 44 writers = new int[3]; 45 this.setPreferredSize(new Dimension (300, 300)); 46 } 47 48 49 public void setRead(int id, boolean state) { 50 readers[id] = (state) ? 1 : 0; repaint(); 52 } 53 54 55 public void setWrite(int id, boolean state) { 56 writers[id] = (state) ? 1 : 0; repaint(); 58 } 59 60 61 public void setWait(int id, boolean isReader) { 62 if (isReader) { 63 readers[id] = -1; 64 } else { 65 writers[id] = -1; 66 } 67 } 68 69 70 protected void paintComponent(java.awt.Graphics g) { 71 super.paintComponent(g); 72 g.setColor(Color.black); 74 g.drawString("Readers", 10, 10); 75 g.drawString("Writers", 10, 140); 76 77 for (int current = 0; current < 3; current++) { 78 if (readers[current] == 1) 80 g.setColor(Color.red); 81 else if (readers[current] == -1) 82 g.setColor(Color.orange); 83 else 84 g.setColor(Color.green); 85 g.fillRect(10 + (current * 50), 30, 40, 60); 86 87 if (writers[current] == 1) 89 g.setColor(Color.red); 90 else if (writers[current] == -1) 91 g.setColor(Color.orange); 92 else 93 g.setColor(Color.green); 94 g.fillRect(10 + (current * 50), 170, 40, 60); 95 } 96 97 g.setColor(Color.green); 99 g.fillRect(160, 120, 10, 10); g.setColor(Color.orange); 101 g.fillRect(160, 140, 10, 10); g.setColor(Color.red); 103 g.fillRect(160, 160, 10, 10); 105 g.setColor(Color.black); 106 g.drawString(" : Inactive", 170, 128); 107 g.drawString(" : Waiting", 170, 148); 108 g.drawString(" : Active", 170, 168); 109 } 110 } 111 112 | Popular Tags |