/* * * Ringid muudavad värve. * Autor: Paavo Viilup * */ import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.util.*; public class Ringid extends Applet implements MouseMotionListener, MouseListener{ LinkedList xlist=new LinkedList(); //koordinaatide hoidmiseks LinkedList ylist=new LinkedList(); public Ringid(){ addMouseListener(this); addMouseMotionListener(this); } public void mouseDragged(MouseEvent e){} public void mouseMoved(MouseEvent e){ Graphics gr=Ringid.this.getGraphics(); //kindlasti saab ka nii teha, et Graphics on igalpool g, aga for(int i=0; ie.getY()&&ypos+100>e.getY()){ //muudetakse värve. Kui teha palju ringe, siis saab selgelt aru, gr.setColor(Color.red); //kust piirid lähevad gr.fillOval(xpos, ypos, 30, 30); } if(xpos+101>e.getX()&&xpos+200>e.getX()){ gr.setColor(Color.blue); gr.fillOval(xpos, ypos, 30, 30); } } } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){ Graphics g=Ringid.this.getGraphics(); Integer iks=new Integer(e.getX()-15); Integer igrek=new Integer(e.getY()-15); //ringide tegemine. Puust ja punaselt jällegi. xlist.add(iks.toString()); ylist.add(igrek.toString()); g.fillOval(e.getX()-15, e.getY()-15, 30, 30); } public static void main(String args[]){ Frame f=new Frame("Ringid"); f.setSize(500, 500); f.add(new Ringid()); f.setVisible(true); } }