import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Indikaator extends JPanel implements MouseListener{ double protsent; java.util.List kuularid=new LinkedList(); public Indikaator(double protsent){ this.protsent=protsent; addMouseListener(this); } public void lisaProtsendiKuular(ProtsendiKuular p){ kuularid.add(p); } void teavitaProtsendiMuutusest(){ for(Iterator it=kuularid.iterator(); it.hasNext();){ ProtsendiKuular k=it.next(); k.protsentMuutus(this, protsent); } } public void muudaProtsent(double uusprotsent){ this.protsent=uusprotsent; teavitaProtsendiMuutusest(); repaint(); } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){ this.muudaProtsent(100*e.getY()/getHeight()); } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void paintComponent(Graphics g){ super.paintComponent(g); g.fillRect(0, 0, getWidth(), (int)(protsent/100*getHeight())); } }