DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Applet help

  1. #1
    Join Date
    Mar 2005
    Location
    Airzona
    Posts
    7

    Applet help

    Alright when u click down now it shows a circle , then u realease the mouseclick and it says then u click again the cirlce moves to that spot, i was wondering how you would get it so when u click down and hold the drag your mouse around the applet it just keeps making circles. then u realease and the circles go away

    thanks for the help

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Use this

    Code:
    class DrawPanel extends JPanel implements MouseListener, MouseMotionListener {
      boolean isDragging=false;
      Point mousePos=null;
      public DrawPanel () {
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
      }
      private void wipeScreen(Graphics g) {
        Color c=g.getColor();
        g.setColor(Color.white);
        g.fillRect(0,0,this.getSize().width,this.getSize().height);
        g.setColor(c);
      }
      public void paint (Graphics g) {
        if (isDragging) {
          g.drawOval(mousePos.x,mousePos.y,50,50);
        } else {
          wipeScreen(g);
        }
      }
      /**
       * MouseListener implementation
       */
      public void mousePressed(MouseEvent e) {}
      public void mouseReleased(MouseEvent e) {
        isDragging=false;
        repaint();
      }
      public void mouseClicked(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      /**
       * MouseMotionListener implementation
       */
      public void mouseDragged(MouseEvent e) {
        isDragging=true;
        mousePos=e.getPoint();
        repaint();
      }
      public void mouseMoved(MouseEvent e) {}
    
    }
    eschew obfuscation

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links