Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:06:31+00:00 2026-05-23T19:06:31+00:00

this is the code: import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.Vector; public class

  • 0

this is the code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Vector;


public class PainterNN extends Applet implements MouseListener, MouseMotionListener{

    class MyShape{
    int mx;
    int my;
    Color mc;

    MyShape(int x, int y, Color c){
        mx=x;
        my=y;
        mc=c;
        }

    void Render(Graphics g){
          g.setColor(mc);
        g.fillOval (mx,my,10,10);
        }
}


    Vector<MyShape> vec = new Vector();   


    public void init() {
        }

    public void paint(Graphics g) {
        for(int i =0; i < vec.size() ; i=i+1){

        MyShape s = vec.elementAt(i);
        s.Render(g);
        }
    }

    public void mouseEntered( MouseEvent e ) {
      // called when the pointer enters the applet's rectangular area
   }
           public void mouseExited( MouseEvent e ) {
      // called when the pointer leaves the applet's rectangular area
   }
           public void mouseClicked( MouseEvent e ) {
      // called after a press and release of a mouse button
      // with no motion in between
      // (If the user presses, drags, and then releases, there will be
      // no click event generated.)
   }
           public void mousePressed( MouseEvent e ) {  // called after a button is pressed down
      repaint();
      // "Consume" the event so it won't be processed in the
      // default manner by the source which generated it.
      e.consume();
   }
   public void mouseReleased( MouseEvent e ) {  // called after a button is released
       repaint();
      e.consume();
   }
   public void mouseMoved( MouseEvent e ) {  // called during motion when no buttons are down
      e.consume();
   }
   public void mouseDragged( MouseEvent e ) {  // called during motion with buttons down
     int mx = e.getX();
     int my = e.getY();

      vec.add(new MyShape(mx,my,new Color(0,255,0)));
      repaint();
      e.consume();
   }


}

It should draw circles at mouse drag but it didn’t. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:06:32+00:00Added an answer on May 23, 2026 at 7:06 pm

    You have to add the mouse listeners.

    public void init()
    {
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
    }
    

    Hint: Try using Ctrl – Shift – F in your IDE. Normally, it will beautify your code. (Eclipse and NetBeans support this)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the complete code : import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Thread;
Consider this code: import socket store = [] scount = 0 while True: scount+=1
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
This is my code: import datetime today = datetime.date.today() print(today) This prints: 2008-11-22 which
I've got this code: Entry.h #import <Foundation/Foundation.h> @interface Entry : NSObject { id object;
I have this code in my forms.py : from django import forms from formfieldset.forms
This piece of code is from Adobe docs : package { import flash.display.Loader; import
I'm trying to import a Python module in a C# code like this: var
Let's say I have some code (using CherryPy) that looks like this: import cherrypy
import javax.swing.*; // For JPanel, etc. import java.awt.*; // For Graphics, etc. import java.awt.geom.*;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.