Pastebin
81829 geplaatste codes! 

Deprecated: Assigning the return value of new by reference is deprecated in /home/joel/domains/plaatscode.be/public_html/toon.php on line 13

Plaats #33076 (Java)

Gepost op 19-10-2008 13:49 door keffie91
Downloaden als .txt-bestand - Bewerk en post opnieuw
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.util.*;
  5. public class Painter extends JPanel {
  6.         private Vector Lines = new Vector(); /* Vector to keep track of  all
  7.         the lines that are drawn */
  8.         private Vector Rectangles = new Vector();/* Vector to keep track of
  9.          all the rectangles that are drawn*/
  10.         private Line newL; // Instantiate a new Line see Line.java
  11.         private Rectangle newR;// Instantiate a new Rectangle see Rectangle.java
  12.        
  13.         public Painter(){
  14.                 setBackground(Color.WHITE);
  15.                 addMouseListener(l1);
  16.         }
  17.  
  18.         public void paintComponent(Graphics g){
  19.             /* draw all the lines in the Vector */
  20.                 super.paintComponent(g);
  21.                 for(ListIterator i=Lines.listIterator();i.hasNext();){
  22.                         ((Line) i.next()).draw(g);
  23.                        
  24.                 }
  25.         }
  26.         MouseListener l1 = new MouseAdapter(){
  27.                         public void mousePressed(MouseEvent e){
  28.                                 newL = new Line(e.getPoint(),e.getPoint());/*
  29.                                  start a new Line and get the point where you
  30.                                  pressed the mouseButton*/
  31.                         }
  32.                         public void mouseReleased(MouseEvent e){
  33.                                 newL.p2 = e.getPoint();/* get the point where
  34.                                  you released the mouse*/
  35.                                 Lines.add(newL);/*add the new line to the
  36.                                  vector so that it can keep track of it*/
  37.                                 repaint();/*repaint, draw all the lines again */
  38.                         }
  39.         };
  40. }
© 2014 Sitemasters.be - Gehost door Vircon