import java.awt.Color; import java.awt.Graphics; import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; import javax.swing.JFrame; /* * Created on Aug 30, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author admin * * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates */ public class HelloMouseList extends JFrame implements MouseMotionListener, MouseListener, KeyListener { int x, y; boolean flipped ; int red; static HelloMouseList frame; ArrayList marks = new ArrayList(); ArrayList dots = new ArrayList(); public void paint(Graphics g) { //this is where we paint //g.fillOval(x - 2, y - 2, 4, 4); g.clearRect(0,0,frame.getWidth(), frame.getHeight()); g.setColor(new Color(red,0,0)); for (int i = 0; i < marks.size(); i++){ ArrayList theseDots = (ArrayList) marks.get(i); for (int j = 0; j < theseDots.size(); j++){ Point thisPoint = (Point) theseDots.get(j); if (flipped){ g.fillOval(frame.getWidth() - thisPoint.x - 2, thisPoint.y - 2, 4, 4); }else{ g.fillOval(thisPoint.x - 2, thisPoint.y - 2, 4, 4); } } } } public void destroy() { System.out.println("Kill Application"); frame.setVisible(false); frame.dispose(); System.exit(0); } public static void main(String[] args) { //this is called when it is an application frame = new HelloMouseList();//"rtsp://128.122.151.241/sve204/test1.mov"); frame.addWindowListener(new java.awt.event.WindowAdapter() { //for public void windowClosing(java.awt.event.WindowEvent e) { frame.destroy(); } }); frame.setTitle(frame.getClass().getName()); frame.setSize(320, 240); frame.setVisible(true); frame.addMouseMotionListener(frame); frame.addMouseListener(frame); frame.addKeyListener(frame); } /* * (non-Javadoc) * * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) */ public void mouseDragged(MouseEvent arg0) { x = arg0.getX(); y = arg0.getY(); dots.add(new Point(x,y)); //repaint(); } public void mouseMoved(MouseEvent arg0) { // TODO Auto-generated method stub } public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub dots = new ArrayList(); } public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub marks.add(dots); repaint(); } public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } public void keyPressed(KeyEvent e) { if ( e.getKeyChar() == 'f') flipped = ! flipped; if ( e.getKeyChar() == 'c') red = red + 10; repaint(); } public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } }