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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:32:00+00:00 2026-06-13T12:32:00+00:00

So in class we are making a Java program. We are trying to use

  • 0

So in class we are making a Java program. We are trying to use the paint(Graphics g) function in the JFrame. We have tried it in the past (weeks ago) and it used to work. But now it doesnt (or we made a mistake somewhere). We have also tried to use paintComponent(Graphics g) but nothing seems to work.
Here is our code:

public class MainAc {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Class Paint");       
        JButton button = new JButton("Click for more");             
        frame.setSize(800, 600);    
        frame.add(button);
        frame.setLayout(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        button.setLayout(null);
        button.setLocation(100,100);
        button.setSize(200,100);
        frame.setVisible(true);     
    }
    public void paint(Graphics g){
        g.drawString("Hello", 200, 50);
    }
}
  • 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-13T12:32:02+00:00Added an answer on June 13, 2026 at 12:32 pm

    So what you’re doing, is implementing a paint method inside your own MainAc class, not the JFrame.

    Your MainAc class itself, should derive from the JFrame.

    The code below should work. If you don’t understand inheritance, you should look over your class notes, it’ll be in there.

    public class MainAc extends JFrame {
    
        public static void main(String[] args) {
            new MainAc();
        }
        
        public MainAc() {
            super("Class Paint");       
            JButton button = new JButton("Click for more");             
            setSize(800, 600);    
            add(button);
            setLayout(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            button.setLayout(null);
            button.setLocation(100,100);
            button.setSize(200,100);
            setVisible(true);
        }
        
        public void paint(Graphics g) {
            super.paint(g);
            g.drawString("Hello", 200, 50);
        }
        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java program that I am trying to generate 3 outputs for,
I'm making my first game in Java with Slick2d and I created a class
I'm making a tool to dynamically display the sourcecode of running java class. I
I am working on a project with MySQL,Hibernate,Java,GWT I am making an entity class
Here is my problem. I have created a pretty heavy readonly class making many
Does making the below class final (adding public final class) have any real impact
So I was making Java, and made a nice little program. Here's the code:
I'm making a blackjack program in Java, and I was starting to write the
I'm currently making a small program to teach me some new Java, and I'm
I'm making a simple paint program and am stuck with getting a certain part

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.