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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:14:08+00:00 2026-06-15T03:14:08+00:00

So my program consists of two classes 1. My main class handling GUI which

  • 0

So my program consists of two classes
1. My main class handling GUI which extends JFrame so I need to instance it to configure my JFrame .
2. MyClass which requests and processes data requested from server using an API which has to have an instance of an API class which handles requests in addition . (its a runnable class and implents a wrapper from API)

So if I simply instance MyClass like (Runnable Processor = new MyClass()), inside my main class and create a thread with it and run . I cant access methods of MyClass or API class methods (i am specifically interested in a connection killer method). Im trying to access it like Processor.API.eDisconnect(). That doesnt work.

But if do it like so : Create an Arraylist of MyClass then add an instance of MyClass to the list . Create a thread like Thread myThread = new Thread(List.get(0)) . I can access my methods of API class like List.get(0).API.eDisconnect().

So why does the second method work ? the only difference that the class instance is an independent variable or is in a list .

Is it proper practice what problems can occur ? is there a better way to do it ?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basket;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 *
 * @author ivan
 */
public class Basket extends JFrame implements ActionListener{
    protected List<TwsHandler> TWS = new ArrayList<>();
    public static void main(String[] args) 
    {
       Basket main = new Basket();
       main.Launch();
    }
    public void Launch()
    {
        TWS.add(new TwsHandler());
        BorderLayout MainLayout = new BorderLayout();
        JButton Start = new JButton("Start");
        Start.addActionListener(this);
        Start.setActionCommand("Start");
        JButton Stop = new JButton("Stop");
        Stop.addActionListener(this);
        Stop.setActionCommand("Stop");
        this.setLayout(MainLayout);
        this.add(Start , BorderLayout.SOUTH);
        this.add(Stop , BorderLayout.WEST);
        this.addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e){System.exit(0);}
        });
        this.setTitle("Option basket robot");
        this.setBounds(100, 100, 800, 600);
        this.setVisible(true);

    }
    @Override
    public void actionPerformed(ActionEvent e) 
    {
        switch (e.getActionCommand()) {
            case "Start":
                Thread Processor = new Thread(TWS.get(0));
                Processor.start();
                break;
            case "Stop":
                System.out.println(TWS.get(0).Eclient.isConnected());
                break;

        }
    }
}
  • 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-15T03:14:10+00:00Added an answer on June 15, 2026 at 3:14 am

    The only difference is that in the first case, you’re referencing a MyClass instance as a Runnable, whereas in the second case, you’re referencing it as a MyClass (through an ArrayList, which doesn’t serve any purpose).

    Instead of

    Runnable processor = new MyClass();
    

    use

    MyClass processor = new MyClass();
    

    since you want to be able to call MyClass methods.

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

Sidebar

Related Questions

I am working on a program which consists of two parts Service component will
I have a .NET 4 app which consists of the app and two class
The code below consists of two classes : SmartForm (simple model class) SmartForms (plural
I have a very small c++ program that consists of two files: main.cpp and
I have a program which consists of two simple Java Swing files. How do
A C++ program consists of two .cpp files, main.cpp and f.cpp. Code of the
I'm currently trying to optimize my program. I have a large database which consists
When you're writing a program that consists of a small bit of main logic
My program consists of a large graphing UI control that I need to spend
THIS IS HOMEWORK: I have a program that consists of two winforms and three

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.