Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-2008, 10:50 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
Rep Power: 3
willemjav is on a distinguished road
Default communication between classes
Imagine there are two classes (actually there five, but lets simplify the example). Class A, the top class, contains the final static-void-main method, and class B sets all GUI stuff (please do not ask me way). A button event of class A should trigger large sequences of things and the user (besides doing other things at the GUI panel of class B) could push the button at any time.
How should this be implemented? A wait loop at class A, will block other GUI activity of class B! The events of the object of class B, created at class A, are not noted right away to class A (events happen in class B).
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-31-2008, 11:09 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Post no wait states
Code:
class A {
  B b;
  A(B bee){
  b = bee;
Class A now can do and call methods of a class B on the name "b" thus:
Code:
 b.doSomething(data);
In the class that has the button pushing stuff, we have a remarkably simple adjunct but that requires you grasp this first,.... then we still have to drive the controller class in a non-blocked manner using the clock I described in the don't ask me to which you refer.
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-01-2008, 01:26 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
A button event of class A
This is a contradiction if all the GUI is in class B.
Quote:
trigger large sequences of things
These things should not be done on the thread of the listener (also call EDT). When the button is pressed, start a thread to do the "large sequences". This will leave the GUI alive to allow the user to
Quote:
push the button at any time
Quote:
The events of the object of class B, created at class A, are not noted right away to class A (events happen in class B).
No idea what this means.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-01-2008, 01:26 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
Rep Power: 3
willemjav is on a distinguished road
Default
so b is a variable of the of type B. A´s constructor takes bee is an argument passed in as type B assigned to b... you might want to post this in eranga´s quiz?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-01-2008, 01:28 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
Rep Power: 3
willemjav is on a distinguished road
Default
norm you are right it is a button event of class B
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-01-2008, 01:36 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
Rep Power: 3
willemjav is on a distinguished road
Default
"The events of the object of class B, created at class A, are not noted right away to class A (events happen in class B)."

The events happen in class B
Class A creates an object of class B. lets say b
(B b = new B();
b.button reads out the button at class A
BUT I DO NOT KNOW WHEN THE BUTTONS GETS PUSHED
So I start a thread with a spinning loop
do {} while (button pressed)
exit the run()
but that is what you do not like, norm?
(anyway my cpu has nothing better to do)
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-01-2008, 01:37 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default progress
this is moving in the right direction,... we have several classes to tangle with and as well a method call can do the passing in of a reference - that is more to your thinking than some rigid style. You will need several classes...

a GUI class
a Clock class
a MasterController
one or more data classes

Do not drive the master controller with events, which is what you will try to do.
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-01-2008, 01:50 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
Rep Power: 3
willemjav is on a distinguished road
Default
Thanks nick, its late in spain
I´ll go for a sleep
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 09-01-2008, 04:19 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
So I start a thread with a spinning loop
do {} while (button pressed)
exit the run()
Then what??? when you exit the loop?
Can you have the button press start whatever is supposed to be started when the loop exits?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 09-01-2008, 05:46 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Post Norms got it
As usual, Norms on top of the systems issues at hand.

willemjav, it sorta runs like this.....
Code:
do{
if(button_pressed){shipData();yield();}
else{yield, sleep or whatever}
that's in the PlaySequence class, which has a boolean... run / stop

then in MainControllerClass:
Code:
ControllerClass{
   PlaySequence sequencer;
   ControllerClass(PlaySequence ps){
   sequencer = ps;
}
and in the ControllerClass we have in the event handler:
Code:
if(event typeof button event){
   sequencer.button_pressed = true / false;//
which can also be done by a method call.

The work at hand is not unlike looking at one's image in a mirror in the morning when waking up and at that instant where you gain enough conciousness to differentiate the image in the mirror from the actual coporeal body and as well disentangle that from your thoughts, which is also contradistincted from the thoughts of others......

Some languges, many non ISO Latin-1 languages, do not even have words for this, probably some relaxed contemplation is best for this work. That is what works for me. In fact I no longer even put this stuff in a main.....
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 09-01-2008, 11:08 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Trying to help you with your question brings us to class design and object-oriented programming ideas. Although there are many ways to put things together there are some general ideas/guidelines that seem to work well. Ususally we put the main method in the gui class and center the user-interaction/event-listening activity in it. The event listeners then call methods in the various classes to make things happen.
This gives the user direct control of what happens in the app and helps avoid awkward class communication situations. Sometimes it is wise to step back and have a look at the overall design and reconsider how you've put things together.
It is possible that you have worked out a model for your music and are later/now trying to find a way to show it in a gui. If so then this may be a good time to consider design/redesign.
However, if you are well past this point and your class design makes sense to you and you want to continue to develop this idea of having class A "wait" for some user input from class B I have two suggestions:
1 — have class A implement the ActionListener interface and register it as a listener with the button in (your gui) class B. Class A will then know when the user presses the button and is ready to trigger the large sequence.
2 — if there is a process running in A and it must block/wait for the user to press the button in B (sounds like what you are asking for) then you could try something along the lines of the producer-consumer technique (illustrated in the concurrency trail in the java tutorial) which uses the wait and notify/notifyAll methods with a while loop.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jar and War communication in an Ear madanmohanp Advanced Java 1 08-02-2008 02:39 PM
inter process communication ibtehal Networking 5 06-23-2008 02:35 AM
Communication with c++ mathias Advanced Java 1 08-07-2007 07:47 AM
how To Use Https Connection For Communication fred Advanced Java 2 08-01-2007 05:59 PM
applet servlet communication hardc0d3r Java Applets 1 07-12-2007 07:58 PM


All times are GMT +2. The time now is 01:40 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org