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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:14:26+00:00 2026-05-23T06:14:26+00:00

I am trying to access a form which is not static from another class

  • 0

I am trying to access a form which is not static from another class which is also not static. I’d like to use a member in the class….

Public Class MainForm
public void setConsoleText(String Text){
    jTextArea1.append(Text);
}

I need to know a way to reference this setter from my class “Log” which is basically where data goes to be parsed and logged. I want it to be like this:

    private  void consoleOut(String data) {
        System.out.println(data);
        MainForm.setConsoleText("data");
    }

I cannot access this method.. I can only access MyForm.Class. Is there a way to reference the one that’s been instantiated, or all of them in this virtual machine? It really doesn’t matter as there will only be one of these running in this instance of the Java VM.

I just can’t seem to figure this one out.

  • 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-23T06:14:27+00:00Added an answer on May 23, 2026 at 6:14 am

    You need to give Log a non-static MainForm variable and pass reference to the currently visualized MainForm object into the Log class and into this variable. This can be done via a Log constructor parameter or via a setter method. Then you can call methods on this instance (but checking that it’s not null first). Something like:

    public class Log {
       private MainForm mainForm; // our MainForm variable
    
       public Log(MainForm mainForm) {
          // setting the MainForm variable to the correct reference in its constructor
          this.mainForm = mainForm;  
       }
    
       private  void consoleOut(String data) {
         System.out.println(data);
         if (mainForm != null) {
            // now we can use the reference passed in.
            mainForm.setConsoleText("data");
         }
       }
    }
    

    Edit 1

    For instance if you create your MainForm object and display it from a main method somewhere, create Log along with it and pass the visualized MainForm into the Log constructor, something like so:

    public static void main(String[] args) {
       MainForm myMainForm = new MainForm();
       // ... whatever code is necessary to set up the 
       // ... MainForm object so it can be visualized
       myMainForm.setVisible(true); // and show it
    
       Log myLogObject = new Log(myMainForm);
       //...
    }
    

    Note that if this doesn’t help you, you’ll need to post more of your code.

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

Sidebar

Related Questions

I am trying to access a form from a different thread to that on
I am trying to access a form in mechanize with ugly characters in the
I'm trying to get access to a form and its elements. The form is
I'm trying to access the post target action in a jquery function. example: <form
Im trying to access a web service from a remote computer. I managed to
Im trying to access the Magento customer session in another part of my website.
I am trying to access Outlook 2007 from C#. I have installed the PIA
I am trying to create a form in Access based on a table and
Currently I'm trying to set up a Form to create a News-Item from. The
I have an iframe from which I am trying to send a XMLHttpRequest. Here

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.