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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:31:42+00:00 2026-05-18T08:31:42+00:00

How can I bind together two Java classes? I’m programming a 3D opengl program

  • 0

How can I bind together two Java classes?

I’m programming a 3D opengl program where I have several different classes. I know how to bind classes to the main class, but I can’t bind two separate classes together. I have a class Terrain where I have a list containing some data about the terrain. Then I need that data in another class called Figure which isn’t the main class. I have tried to bind these classes together like this:

In Terrain class I have:

Figure fig;

public void bindClasses(Figure fg) {
   fig = fg;
}

And then in the Figure class I have:

Terrain ter;

public void bindTerrain(Terrain tr) {
   ter = tr;
}

And then in both classes I call those functions. Shouldn’t that bind them and their variables? At least that’s how I have bound my classes with the main 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-18T08:31:43+00:00Added an answer on May 18, 2026 at 8:31 am

    Just to start off with terminology. A class is a blueprint that tells you how an instantiated object is – the moment you write new Figure(), you’ve created an instance, an object of the class Figure (often you have several objects of one class). So when you are “binding” above, you are not actually binding classes, you are binding objects.

    The above code is fine. By convention, you often write that sort of things with setters, it’s not necessary to call them that, but a very common pattern is:

    public class Terrain {
    
        Figure fig
    
        public void setFigure(Figure fig) {
           this.fig = fig;
        }
    
    }
    
    public class Figure {
    
        Terrain ter
    
        public void setTerrain(Terrain ter) {
           this.ter = ter;
        }
    
    }
    

    To associate the two together you would in your main class do, which, as you see, is pretty much exactly what you would have already, just using the conventional names.

    public void init() {
    
       Terrain ter = new Terrain();   // create object of class Terrain
       Figure fig = new Figure();     // create object of class Figure
    
       ter.setFigure(fig);
       fig.setTerrain(ter);
    
    }
    

    If there’s a relationship between the two objects, for instance, you can’t create a figure without having a terrain to put it in. Which would make terrain almost “own” figure. You could indicate this by using the constructor on figure.

    public class Figure {
    
        Terrain ter
    
        // constructor requires an instance of Terrain, 
        // since the figure must always be placed in a terrain
        public Figure(Terrain ter) {
    
           this.ter = ter;
    
           // let terrain know this is the main figure.
           ter.setFigure(this);          
        }
    
    }
    

    Now your init code would instead look:

    public void init() {
    
       Terrain ter = new Terrain();   // create object of class Terrain
       Figure fig = new Figure(ter);  // create object of class Figure in the terrain
    
       // no setters needed, since figure constructor sets up
       // the relationship.
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.