How to interact with swing components in different classes

I'm just trying to figure out some things in my head about how to get information and from swinging components from other classes.

I have a main class that uses several classes to create a swing gui. How do I start writing information to these components from another class. As far as I understand, I need to use arraylist to store links to these components, but I'm not quite sure how to do this, can someone help me?

+3
source share
2 answers

I would suggest that you are trying to separate the model from the view. Do not store data that matches application logic in the actual components of the GUI.

, , getText .

, , .

+3

:

public class MyFrame extends JFrame implements ActionListener 
{
  private final MyBusinessClass bc = new MyBusnessClass();

  @Override public void actionPerformed(ActionEvent e) {
    this.bc.someBusinessMethod();
  }
}
+2

All Articles