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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:39:53+00:00 2026-05-16T11:39:53+00:00

I am working on a project where I have a class called HGraphic that

  • 0

I am working on a project where I have a class called HGraphic that extends JPanel. This class has a public method called updateNum that receives an integer as a parameter and does some work with it, updating some elements.

This HGprahic class has an instance in the main class of my project (the main class extends JFrame)… I need to call this particular method of HGraphic from the main class sending a variable as parameter.

The problem is that although the method is declared as public I am not able to access to it doing the normal hGraphicInstance.method(variable) as I normally do.

I’ve gone through the JPanel documentation but have not found anywhere that says that you can not access custom methods… or that you can not create setters (another way of doing what I need).

When I instantiate the HGraphic class I use a JComponent class for doing it, could this be the reason?

Do you have any idea or advice? I would really appreciate a bit of light in this matter.. THANKS VERY MUCH!!!

I place the main bits of the code:

// CLASS CAUSING THE PROBLEM ------------------
public class HGraphic extends JPanel {

    // Attributes
    public int numberOfCoincidences = 0;

    // Constructor
    public HGraphic() {
        super(new BorderLayout());
    }

    public void updateNum(int tmpNum) {
        numberOfCoincidences = tmpNum;
    }
}

// MAIN FRAME CLASS ----------------------------------
public class HSFrame extends javax.swing.JFrame {

    private int newNum = 5;
    private JComponent newContentPane;

    public HSFrame() {
        initComponents();
    }

    private void initComponents() {
        newContentPane = new HGraphic();
        // HERE IS WHERE I WOULD LIKE TO ACCESS THE CLASS METHOD
        // NetBeans say it does not recognize this method :(
        newContentPane.updateNew(newNum);
    }
}

Thank you again!

  • 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-16T11:39:54+00:00Added an answer on May 16, 2026 at 11:39 am

    because your instance (newContentPane) type is JComponent. you need to define it as HGraphic or cast it before method call.

    private ***JComponent*** newContentPane;
    

    needs to change to :

    private HGraphic newContentPane;
    

    or in your method call:

    ((HGraphic) newContentPane).updateNum(newNum);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Foo that has a function that looks like the
I have been working on a Java project for a class for a while
I have project that I'm working on that is going to require a webserver.
I'm working on a project where I have 2 web services that need the
I am working a project that does not have a trunk / branches /
I have created a class library called AddServiceLibrary in which I have a method
I'm working on a grails legacy project. A domain class called User exists. It
I have been working Quartz framework in my grails project with lib called quartz-all-1.7.3.
I am working on a project, and I have a generic abstract type that
In a current project, I have a model called Box that stores items from

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.