import java.awt.*; class Stock extends IntLabel{ private static final int max=30; Stock(Label lb){ super(lb); } boolean full(){ return get()>=max; } boolean empty(){ return get()<=0; } synchronized void buy(){ while(empty()){ try{ wait(); }catch(Exception e){} } super.dec(); notifyAll(); } synchronized void supply(){ while(full()){ try{ wait(); }catch(Exception e){} } super.inc(); notifyAll(); } }