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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:46:05+00:00 2026-05-30T08:46:05+00:00

I am trying to import java.awt.*; into my class in Greenfoot but when I

  • 0

I am trying to import java.awt.*; into my class in Greenfoot but when I call a method, paintComponent(), I get an error saying that the method was not found.

The Greenfoot website states that native classes must be imported manually (http://www.greenfoot.org/doc/native_loader) and each native class must be included in my scenario (project).

The website gives a link to the native class loader but not the library containing the java.awt classes.

It would be great help if somebody could tell me where I can download the library or let me know if I am on the right track as I am completely new to Java.

Thanks

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
import javax.swing.*;

public class Ground extends Actor
{
   public void act() {
      // Add your action code here.
   }

   public void paintComponent(Graphics z) {
      super.paintComponent(z);

      z.setColor(Color.BLUE);
      z.fillRect(0, 0, 100, 100);
   }
}
  • 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-30T08:46:06+00:00Added an answer on May 30, 2026 at 8:46 am

    paintComponent() is a method in Swing — i.e., classes in package javax.swing. The classes in java.awt don’t have such a method. It’s introduced in javax.swing.JComponent, so all subclasses of JComponent — i.e., JButton, JPanel, etc — have it.

    To draw a Greenfoot Actor, you create and return a GreenfootImage object. Here is its API. I think the correct equivalent to the above is something like

    public class Ground extends Actor {
        public GreenfootImage getImage(){
            GreenfootImage image = new GreenfootImage(100, 100);
            image.setColor(Color.BLUE);
            image.fillRect(0, 0, 100, 100);
            return image;
        }
    }
    

    I don’t know how often getImage() is called; maybe the Greenfoot documentation explains that.

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

Sidebar

Related Questions

I'm trying to print a JFrame using the PrintUtilities Class: package util; import java.awt.*;
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class displayFullScreen extends JFrame { private JLabel
import java.lang.Math; import java.awt.* public class Triangle implements Shape { java.awt.Point a; java.awt.Point b;
I'm trying: import commands print commands.getoutput(ps -u 0) But it doesn't work on os
I am trying to import the contact list from gmail using libgmailer.php but I
I've been trying to import a table from oracle 10g into SQL Server 2005
So I am trying to import a module foo that contains directories bar and
I am trying to import an excel file into a data table using GemBox
I am trying to import BlackBerry code and into Eclipse from SVN. It isn't
I’m trying to import fixed width data from text file into SQL Server Express

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.