public MyCanvas(int num_fields, int field_size, int x_offset, int y_offset) { this.num_fields=num_fields; this.field_size=field_size; this.x_offset=x_offset; this.y_offset=y_offset; array=new int[num_fields][num_fields]; setBackground(Color.white); setSize(2 * x_offset + num_fields * field_size + 30, y_offset + num_fields * field_size + 50); for(int i=0; i < num_fields; i++) for(int j=0; j < num_fields; j++) array[i][j]=0; }
public void componentResized(ComponentEvent e) { if(getWidth() <= 0 || getHeight() <= 0) return; createOffscreenImage(false); } });
public void componentResized(ComponentEvent e) { if(getWidth() <= 0 || getHeight() <= 0) return; createOffscreenImage(false); } });
void startSender() { if(sender == null || !sender.isAlive()) { sender=new SenderThread(); sender.start(); } }
@Override public void run() { int cnt=1; while(true) { Util.sleep(1000); MyNotification notif=new MyNotification("home.grown", this, cnt, "hello-" + cnt); notif.setName("Bela Ban"); cnt++; sendNotification(notif); } } }.start();
public void addValueTo(int x, int y, int value) { synchronized(array) { array[x][y]+=value; repaint(); } }
void stopSender() { if(sender != null) { sender.stopSender(); sender=null; } }
public void coordinatorChosen() { coordinator=true; repaint(); }
public void clearPanel() { if(panel != null) panel.clear(); }
public String toString() { return "[" + x + ',' + y + ": " + printType() + '(' + val + ")]"; } }
protected void showStatus(final String msg) { new Thread() { public void run() { synchronized(status) { status.setText(msg); Util.sleep(2000); status.setText(""); } } }.start(); }
public void run() { StompDraw.this.stop(); } });
public ReplicatedHashMapDemo() { super(); addWindowListener(this); }
public void clearPanel() { if(panel != null) panel.clear(); }
public void subtractValueFrom(int x, int y, int value) { synchronized(array) { array[x][y]-=value; repaint(); } }
public void divideValueBy(int x, int y, int value) { if(value == 0) return; synchronized(array) { array[x][y]/=value; repaint(); } }
public void setValueAt(int x, int y, int value) { synchronized(array) { array[x][y]=value; } repaint(); }
public void multiplyValueWith(int x, int y, int value) { synchronized(array) { array[x][y]*=value; repaint(); } }