Communicating between classes

I have a form that is divided into two classes. Each class represents the widgets on part of the form. What is the best way to allow these classes to share data between each other and update each other.

Example: Button in class A is clicked. Update text field in class C

-------------Problems Reply------------

This is very short what you can do:

public class ButtonFrame extends JFrame implements ActionListener
private TextFieldFrame frame;

public ButtonFrame(TextFieldFrame frame)
this.frame = frame;
// init your components and add this as actionlistener to the button

public void actionPerformed(ActionEvent evt)

The other class:

public class TextFieldFrame extends JFrame
private JTextField field = ...; // init in your constructor

public void notifyButtonPressed()
field.setText("Yes man!! The button is pressed by the user!");

Again, this is very short what you have to do.
You can also work with a Singleton pattern, but this is a better way.

You could create a class that holds all your form-objects. The form classes all know the parent class and communicate over it.

If a button is clicked in class A, class A calls a method in the parent class and the parent class notifies class C to update its text field.

Don't think widget. Design your application on models. Have widgets as windows onto those models. (And don't extend classes unnecessarily.)

Have a look at Mediator pattern, it could give you some ideas.

Also, JFace Databinding framework goal is synchronization of values between objects, although i find it poorly documented and not much fun to use. JFace_Data_Binding

Category:java Views:0 Time:2010-05-05
Tags: java swt

Related post

  • Using Signals for communicating between classes 2012-03-03

    I want to use signals for communicating between my view and my application controller. I have following approach but since I'm beginner in PyQt I don't know if that is the right one. Can anyone tell me If I am on the right path or are there better so

  • Objective C communication between classes 2009-12-23

    I have an AppController class that looks after view/control in my app in the usual way. There's a button on my app's main window in IB that causes AppController to instantiate a new window controller (accountPanelController) and show that secondary w

  • Communication between classes in an android project 2012-04-04

    I've been struggling to solve a problem for over a week. I have a main activity with 3 child classes which extends View. When a touch event happens at a View class, calling a certain method in other 2 View classes synchronize with the event. But I ha

  • Java Communication Between Classes and JFrame JDialog 2010-04-23

    i have written a standalone connect 4 game. next i would like to be able to play it over network and also have a chat function. connect 4 GUI (JFrame) holds -> connect 4 game model i would like to implement connect 4 network GUI(JDialog) (here the

  • Communicating between classes set up in nib, in code? 2010-06-12

    A beginner's question: If, in your nib, you have the File's Owner linked to the ViewController class, and you also have a NSObject-derived class, how do you communicate between the ViewController class and the NSObject class within code? For instance

  • Objective C: Communicating between classes 2010-08-29

    I'm writing an iPhone program that has a login view controller that allows the user to login. I have a method I use within that controller that checks the authentication of the username and password. I'm using the keychain to store the username and p

  • What is the best pattern for two way communication between classes? 2010-12-14

    I have classes that need to communicate with each other. The problem is that if you make one contain the other (a child parent relationship) then things get tricky. You either need to pass an instance of the parent into the child, (then which one do

  • Java - Communication between classes - issue 2011-09-06

    I´m making an analogue clock and I´ve got a problem I cannot solve. I´ve got three classes: main, clock, pointer. Main just creates the clock and starts everything. Clock manages how the clock works and paints it. Pointer defines what the pointers do

  • two way communication between class and superclass 2011-09-15

    [sorry for my weak english] I have my common superclass S for my five specific, but similiar, classes B1, B2, B3, B4 and B5. I want to put 'common' (similiar in each B's) code to S, (and call it by [super myCommonFunction]). It should be ok, but ques

  • Communicating between classes iOS NSObject and UIViewController 2012-03-31

    I have two classes, a class1 which is an NSObject and a class2 which is a UIViewController... From the UIViewController I sent something to class1 to get it to do an action: [class1 doVoidAction]; and in class1 I have: -(void)doVoidAction{ blah blah

  • Communication between local JVMs 2011-02-19

    My question: What approach could/should I take to communicate between two or more JVM instances that are running locally? Some description of the problem: I am developing a system for a project that requires separate JVM instances to isolate certain

  • Calling Between Classes in Blackberry Java 2012-01-27

    I am trying to push a new screen when a bitmap is "clicked" on the screen. For this I have created a Class from this post: Blackberry Clickable BitmapField whose partial code I've posted below: public class CustomMenuButtonField extends Field{ Bitmap

  • Communication between client class library and web service / web service and server class library 2010-07-27

    Wondering what others do / best practice for communicating between layers. This question relates to communication between layers 2-3 and 3-4. Our Basic Architecture (in order) as follows: UI Front End Business Classes Web Services Back End Business C

  • Communication between server and client for WinForms 2008-10-26

    I have 50+ kiosk style computers that I want to be able to get a status update, from a single computer, on demand as opposed to an interval. These computers are on a LAN in respect to the computer requesting the status. I researched WCF however it lo

  • How To Handle Communication Between the Domain and Database Layers? 2009-02-14

    I am fairly new to using separate layers for the business logic (Domain) and database access logic, but in the course of working things out I've come across a problem to which I still feel I haven't found a great solution. Clarification My existing s

  • Interprocess Communication between C++ app and Java App in Windows OS environment 2009-07-30

    We have a C++ application on Windows that starts a java process. These two apps need to communicate with each other (via snippets of xml). What interprocess communication method would you choose, and why? Methods on the table for us are: a shared fil

  • Communication between two DLLs within the same process 2009-07-31

    I have an application that loads "aaa.dll". "aaa.dll" loads two other dlls "bbb.dll" and "ccc.dll". aaa.dll is a third party dll not written by myself. But bbb.dll and ccc.dll are written by me. Is there any way for bbb.dll and ccc.dll to communicate

  • Communication between programs in .NET 2009-08-16

    I want to separate modules of my program to communicate with each other. They could be on the same computer, but possibly on different ones. I was considering 2 methods: create a class with all details. Send it of to the communication layer. This one

  • MVP and communication between GWT widgets 2010-01-29

    If I am using the MVP pattern with GWT, as in the GWT architecture best practices talk from Google I/O from 2009, but have spread out the information into multiple widgets, how should the value object be populated? Say I have a EditPersonView/Present

Copyright (C), All Rights Reserved.

processed in 0.067 (s). 11 q(s)