import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class HiirPallid2 extends JPanel implements MouseListener{ java.util.List pallid=new ArrayList(); JComboBox tyybivalik=new JComboBox(); public HiirPallid2(){ addMouseListener(this); tyybivalik.addItem("Tavaline pall"); tyybivalik.addItem("Hele pall"); setLayout(new BorderLayout()); add(tyybivalik, BorderLayout.SOUTH); } public void paintComponent(Graphics g){ super.paintComponent(g); for(Pall p: pallid){ p.joonista(g); } } public void mousePressed(MouseEvent e){ if(tyybivalik.getSelectedIndex()==0){ pallid.add(new Pall(e.getX(), e.getY())); } if(tyybivalik.getSelectedIndex()==1){ pallid.add(new HelePall(e.getX(), e.getY())); } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ JFrame f=new JFrame("Palliaken"); f.getContentPane().add(new HiirPallid2()); f.setSize(400, 300); f.setVisible(true); } }