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

  • Home
  • SEARCH
  • 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 8336529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:01:09+00:00 2026-06-09T04:01:09+00:00

We override paint method like this public void paint(Graphics g) { g.drawString(msg,xpos,ypos); } If

  • 0

We override paint method like this

public void paint(Graphics g)
{
   g.drawString(msg,xpos,ypos);
}

If we have another method lets say a mousepressed event method

public void mousePressed(MouseEvent me)    
    {
        xpos=me.getX();  // msg, xpos and ypos are variables of class
        ypos= me.getY();
        msg="You pressed mouse";
        repaint();
    }

Why cant we call paint(Graphics g) rather than repaint() ?

  • 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-09T04:01:10+00:00Added an answer on June 9, 2026 at 4:01 am

    You should probably try that. You will notice

    1. You will have to get the Graphics object g somehow.
    2. Calling paint in the body of an event handler is not a best practice because it causes the body of that method to execute on the GUI thread right away, so no more events can be processed until paint returns. OTOH, repaint schedules a paint event to occur at some convenient point in the future and does not make the GUI appear to hang. Granted, in your case, drawString isn’t terribly slow, but in general….

    Here is the classic article on painting, from the Java people themselves.

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

Sidebar

Related Questions

@Override public void onCancel() { // TODO Auto-generated method stub ERROR:The method onCancel() of
I want something like this public abstract class abc { public abstract void test();
I have extended the Application class like this: public class MyApplication extends Application {
i have override validate method and added errors using addFieldError(test, test print); and in
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); savedInstanceState.putString(foo, bar); } @Override public void
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // providers data // db.execSQL(insert into //
I have an interface like the following: package example; import java.awt.Point; public interface Thing
I have a custom listView. The main layout xml is something like this: <?xml
how to clear the surfaceView in android? I have a class like this -
I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so

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.