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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:07:44+00:00 2026-06-12T10:07:44+00:00

I am really new in Java. Thought I had figure some stuff out by

  • 0

I am really new in Java. Thought I had figure some stuff out by now, but I have a problem that proves otherwise!

Ok! Here it is. I have this code (Edited – Not original):

import java.util.*;
import java.awt.*;

public class MyClass extends HisClass
{
    public void drawRectangle(int width, int height)
    {
      int x1 = this.getXPos();
      int y1 = this.getYPos();
      java.awt.Graphics.drawRect(x1, y1, width, height);
    }

    public static void main(String[] args)
    {
      AnotherClass theOther = new AnotherClass();
      MyClass mine = new MyClass(theOther);
      mine.move();
    }
}

The error it gives me is this:

MyClass.java:66: error: non-static method drawRect(int,int,int,int) cannot be referenced from a static context

Can you please provide me with a solution?
It would be very appreciated. Thanks.

  • 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-12T10:07:45+00:00Added an answer on June 12, 2026 at 10:07 am
    java.awt.Graphics.drawRect(x1, y1, width, height);
    

    drawRect method is not static.. You should get an instance of your Graphics class somehow to use it: –

    (graphicsInstance).drawRect(x1, y1, width, height);
    

    Since Graphics class is abstract, so you need to find appropriate way to instantiate your Graphics object, to get graphicsInstance

    You can use GraphicsContext to draw whatever you want to.. GraphicsContext is an object belonging to Graphics class which you can use to drawRect()

    See these post. Might be useful: –

    How do I initialize a Graphics object in Java?

    what is a graphics context (In Java)?

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

Sidebar

Related Questions

I am really new to Java and I read that synchronized is very expensive
I'm new to java and really need some help. I created a command line
I am really new to the programming but I am studying it. I have
I'm pretty new to java and really enjoying learning about it. I have made
I'm pretty new to Java and this has me really confused. I have two
I've been struggled this java problem for some hours, which i first thought was
Edit: I should have probably mentioned that I am extremely new to Java programming.
I'm fairly new to Android programming and to Java in general, but I have
I thought, I would understand Java generics by now. But now I'm helpless again.
I am really new to java (started learning 2 days ago). Sorry if this

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.