Wills
Wills

Reputation: 491

How to access a Jframe Component from a java class and keeping the UI seperate from the logic a observer pattern ?

Environment: I am trying to create a simple data processing application (Read a file and do some processing on the extracted data) The application has to keep the user updated in real time of the processing.I am keeping the UI & logic seperted so that i can re use the logic for other applications .

Problem: I have a Text Area in the UI which has to display the processing information in real time, the UI using JFrame- Home.java (netbeans Drag & Drop). Logic - Utility.java

  1. How can i access a JFrame component(Home.java) in another class(Utility.java) ?

  2. Is it right way to access a UI component & modify it from a logic code ? By doing this increases work effort in reusing the logic class how can i do this ?

Does observer pattern is solution here ?

Upvotes: 0

Views: 250

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347184

It's a loaded question, a lot depends. If I were doing it, I would establish a series of interfaces.

I'd start with a model interface that defines what you logic can actually do. I would then establish a series of listener interfaces that could be registered against this model that would provide the required call backs.

This separates the logic/model for the view. It allows you the flexibility to change any part without adversely affecting the rest of the application

Upvotes: 2

Related Questions