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 8866153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:42:55+00:00 2026-06-14T16:42:55+00:00

I was trying to learn applets and on executing this code, there are no

  • 0

I was trying to learn applets and on executing this code, there are no compile-time errors but the problem is that i m not getting any response to my code. i used simple notepad and appletviewer to get it done. On clicking on the applet, the coordinates should be displayed but it’s not happening.I have tried entering the relevant html code and executing via a browser but the response is the same. Any help will be really appreciated

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="MyMouseApplet.class"
width = "400"
height = "400"> 
</applet>*/

public class MyMouseApplet extends Applet implements MouseListener{
int x,y;
String str=" ";
public void init(){
this.addMouseListener(this);
}
public void paint(Graphics g){
g.drawString(str,x,y);
}
public void update(Graphics g){
paint(g);
}
public void mouseClicked(MouseEvent m)
{
int x = m.getX();
int y = m.getY();
str="x:" + x + "y:" + y;
repaint();
}
public void mouseExited(MouseEvent m){}
public void mouseEntered(MouseEvent m){}
public void mousePressed(MouseEvent m){}
public void mouseReleased(MouseEvent m){}
}
  • 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-06-14T16:42:57+00:00Added an answer on June 14, 2026 at 4:42 pm

    Your mouseClicked function takes x and y out of scope. Do this:

    public void mouseClicked(MouseEvent m)
    {
         //int x = m.getX();
         //int y = m.getY();
         x = m.getX();
         y = m.getY();
         str="x:" + x + "y:" + y;
         repaint();
    }
    

    This will access the fields of your class, not local variables.

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

Sidebar

Related Questions

trying to learn and practice arrays but I have a problem with this small
I am trying to learn 2D graphics. This code below draws a couple of
Trying to learn pointer math better I wrote this code. The intention was to
Trying to learn pointers better I wrote this code. The intention was to print
I've been trying to learn about applets by studying the code for the Welcome
I'm trying learn Python (3 to be more specific) and I'm getting this error:
Trying to learn Ruby, and in a tutorial, I came across this code on
Trying to learn a bit about PDO and is going through this tutorial .
im trying to learn delegates and events in c#, i understand that an event
Trying to learn jquery here so I took a regular javascript snippet that loops

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.