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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:33:40+00:00 2026-05-13T08:33:40+00:00

this is the code: import java.awt.*; import java.applet.*; public class anim1 extends Applet{ public

  • 0

this is the code:

import java.awt.*;
import java.applet.*;

public class anim1 extends Applet{

    public void paint (Graphics g)
    {
        g.drawString("",400,300);
    }

    public static void main(String ad[])
    {
        anim1 a=new anim1();
        Graphics g1;
        a.paint(g1);
    }
}

It says that g1 is not initialized. But how do I initialize an abstract class?

  • 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-13T08:33:41+00:00Added an answer on May 13, 2026 at 8:33 am

    Well there are two issues here 1:

        Graphics g1;
        a.paint(g1);
    

    And you are getting the error that G1 is not initialized. That’s because the variable g1 is never set to anything, and that causes a compile error. To get the code to compile, you would need to, at the very least do this:

        Graphics g1 = null;
        a.paint(g1);
    

    However, that obviously won’t help you out too much. You’ll get a NullPointerException when you try to run your code. In order to actually cause your graphics to draw you need to this:

        anim1 a=new anim1();
        Graphics g1 = anim1.getGraphics();
        a.paint(g1);
    

    However, that still won’t work because Anim1 will not appear on the screen. To get it to appear on the screen you need something like:

    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;
    
    public class So1 extends Applet{
    
        public void paint (Graphics g)
        {
            g.drawString("hello",40,30);
        }
    
        public static void main(String ad[])
        {
    
            JFrame jp1 = new JFrame();
            So1 a=new So1 ();
            jp1.getContentPane().add(a, BorderLayout.CENTER);
            jp1.setSize(new Dimension(500,500));
            jp1.setVisible(true);
    
        }
    }
    

    Now notice, we don’t actually call the paint() function ourselves. That’s handled by the awt, which actually picks the graphics context, and calls our paint function for us. If you want, though, you can pass in any graphics object you want and ask it to draw on to that. (so if you want to draw your component onto an image, you can do it)

    (note, I changed the classname from anim1 to So1)

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Creating index after data insert is more efficient way (it… May 16, 2026 at 6:43 pm
  • Editorial Team
    Editorial Team added an answer button.CheckedChanged += buttonGroup_OnCheckedChanged; I believe that is what you want.… May 16, 2026 at 6:43 pm
  • Editorial Team
    Editorial Team added an answer Assuming that the email indexes stay the same (I think… May 16, 2026 at 6:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
So, I'm getting stuck with this piece of code: import java.util.InputMismatchException; import java.util.Scanner; public
I'm making a TCP Client in Applet mode and I get this strange error...
I have created this applet, It moves mouse to 1000 pos on screen. It
OK so what's the problem with this. I tried using MySQL JConnector for Java
I have a Java Applet that is generating an image. Ultimately, I would like
How do I add background image on this code? i tried everything but the
I been trying to do the question title. Here is my current code: Main.java
ArrayList.remove(int index) is working with the anonymous instance of ActionListener class :- DeleteModule.java :-
I'm a complete n00b in j3d (but an expert in Java). Just starting out,

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.