How do classes talk to each other - newb question

Hey, im fairly new to java and have a problem
If i have my main class (main) instantiate a new object of a class (ftp)
how does ftp return information to main after it has been created,
i might need the information at any time so i can't use the constructor again, can i?
i realise main could call a method of ftp to return some information but i cant have it doing it every second when it might only need the information every 10 minutes
can i create my own eventlistener in main to listen for something i can start in ftp?
i can up some code if you like cos i'm sure that makes no sense but any help is very welcome :)

A listener/observer pattern can help, as you have noted.
public class DataClass {
    private int field1;
    //private String field2;
    private List<DataChangedListener> listenerList = new ArrayList<DataChangedListener>();
    public void setField1(int newVal) {
       field1 = newVal;
       fireUpdate();
    public void getField1() { return field1; }
    private void fireUpdate() {
       for ( DataChangedListener listener: listenerList )  {
          listener.dataChanged(this);
    public void addListener( DataChangedListener listener) {
       listenerList.add(listener);
public interface DataChangedListener {
   public void dataChanged(DataClass source);
}

Similar Messages

  • Making classes talk to each other, getting my head around object-oriented

    How many questions can I ask before people get annoyed? Hope I'm not asking too many. This is probably a dumb question, but trying to do this whole object-oriented thing is making my head spin. I want my program to make something happen in Panel 2 when there's a mouse event in Panel 1 and vice versa. In psuedo-code (very pseudo):
    panel1.addMouseListener(new MousyListener());
    private class MousyListener implements MouseListener
              public void mouseEntered(MouseEvent event) {
                   Make stuff happen in panel2
    I don't even know where to start. I've looked at the tutorials,I've looked in my books, but I still as confused as ever. Could someone please give me a hint as to how I make this happen?

    codinatrix wrote:
    How many questions can I ask before people get annoyed? Hope I'm not asking too many. You can ask as many questions as you like.
    What is annoying is when people cross post the same question. Or when people ask 37 obviously exam type questions in the span of 5 minutes. But as you're not doing either of those don't worry about it.
    This is probably a dumb question, My personal motto (gained by my personal experience) is "there's no question so profound you won't feel like an idiot later for not knowing".
    but trying to do this whole object-oriented thing is making my head spin.Ah yes. It will do that.
    I want my program to make something happen in Panel 2 when there's a mouse event in Panel 1 and vice versa. In psuedo-code (very pseudo):A number of suggestions for you.
    1) When posting code on this forum please make sure and use the code formatting tags. You can do this by selected the code in the posting message box and clicking the CODE button.
    2) I would stay well clear of Swing for awhile. It (and GUI in general for that matter) is not the easiest way to learn OO ness. In fact, in my opinion, it's about the hardest. I don't know where you are with your learning and what you know and don't know though so this may be out of place. If not though I would recommend one to play around with interfaces and abstract classes for awhile. I think once one understands the point of an abstract class one is well on the way to a solid foundation of Java OOness.
    3) This will contradict point 2 but for Swing you should learn about the MVC pattern. Here are a couple of links on the subject http://en.wikipedia.org/wiki/Model-view-controller and http://java.sun.com/blueprints/patterns/MVC.html
    MVC is important because it explains the how-to and why of what one should do with OOness when it comes to GUI.
    4) Don't be afraid to get it wrong. The best way to learn this stuff is by practice. Do it in a way you understand and that makes it work. Then go back and think how you could do it better. Think about how you could encapsulate your classes. Think about how you can seperate the logic of your application from the GUI.
    Good luck.

  • HT5621 My Apple ID on my iphone icloud is different to my apple id on my pc icloud. As a result, they don't talk to each other. My phone  icloud account is for 25 Gigs. but my pc has 5 Gigs but none used.

    My iPhone iCloud uses one of my Apple ID and the account is a 25 Gig storage. I tried to set up icloud on my pc and for some reason it seems to be linked to a different Apple id with a 5 Gig account. Obviously the two don't talk to each other but I don't know how to change one or other so they will sync.

    Try the following....
    Go to Settings>icloud, scroll to bottom of screen and tap Delete Account.  Then log in using a different ID.

  • NetWeaver XI components are not talking to each other

    I am an XI  consultant, i dont have proper Basis support at my client, since they are fond of only ABAP stack.
    They installed netweaver xi from the market place.
    I am unable to import any SWCV (even SAP BASIS) from SLD to IR and IR menu is blank.
    Unable to find list of adapters in Integration Directory.
    RWB -component monitoring is blank .
    SLD- creation of products,SWCV,Technical Sys,Buss Sys is possible.
    In conclusion i can say that they all are not co-operative and not talking to each other
    And also i want to know wheather xi 7.0 is compatable to databases Oracle 8.0.3 and Oracle 8.0.4

    Hi Venkata,
    Does the XI post Installation steps done by the team or not? It seems that there is some steps missing while doing the XI installation. Talk to to the BASIS team and tryu to find out the solution.
    >>> Unable to find list of adapters in Integration Directory.
    Check thisblog for it:
    /people/venugopalarao.immadisetty/blog/2007/03/15/adapter-engine-cannot-be-found-in-integration-directory
    >>> And also i want to know wheather xi 7.0 is compatable to databases Oracle 8.0.3 and Oracle 8.0.4
    In my view, yes. XI is compatible with all the versions of Oracle Database above version 8 but never tried it.
    Reward points if helpful. *
    Regards,
    Subhasha Ranjan

  • When syncing 2 iphones to itunes how do you avoid getting each others apps

    When you sync 2 iphones to itunes how do you avoid
    getting each others apps

    For some reason without syncing
    when I download an app the 2 phones
    get the same app. They are 2 different
    phones with 2 different apple IDs

  • How would 2 people call each other using facetime if both were in a foreign country but staying at different locations within that country?

    How would 2 people call each other using facetime if both were in a foreign country but staying at different locations within that country?

    It's tied to the Apple ID also - I believe it would use that to find the right person/device.
    Perhaps this article would help: http://support.apple.com/kb/HT4319. It looks like you may want to go in through your contacts and make the call.
    If you're concerned about data charges, put your phone in Airplane mode before trying to Facetime. That will prevent it from trying to make a call over your cellular data.
    ~Lyssa

  • Can't get 2 VM nodes to talk to each other on OEL7

    Greetings -
    I am planning to install RAC 11gR2 on OEL7. I got the Oracle VM machines up and running. I can access internet successfully with no issues. Also if I am on Node-1 and ping its IP, it works fine.
    But when I try to ping Node-2 from Node-1 and vice virsa, I get unreachable  message.
    Below is my setup hots setup:
    [oracle@racdev01 Desktop]$ cat /etc/hosts
    # loopback
    127.0.0.1       localhost.localdomain        localhost
    # Public
    192.168.56.71   racdev01.localdomain         racdev01
    192.168.56.72   racdev02.localdomain         racdev02
    # Private
    192.168.10.1    racdev01-priv.localdomain    racdev01-priv
    192.168.10.2    racdev02-priv.localdomain    racdev02-priv
    # Virtual
    192.168.56.81   racdev01-vip.localdomain     racdev01-vip
    192.168.56.82   racdev02-vip.localdomain     racdev02-vip
    # SCAN
    192.168.56.91   rac-scan.localdomain         rac-scan
    192.168.56.92   rac-scan.localdomain         rac-scan
    192.168.56.93   rac-scan.localdomain         rac-scan
    Pinging both public & private IPs from node-1 to node-2 and vise-versa keeps failing:
    $ ping racdev02
    $ ping racdev02-priv
    >> My network:
    Node-1:  Ethernet (enpOs8) => 192.168.56.71   (public)
    Node-1:  Ethernet (enpOs9) => 192.168.10.1     (private)
    Node-2:  Ethernet (enpOs8) => 192.168.56.72   (public)
    Node-2:  Ethernet (enpOs9) => 192.168.10.2     (private)
    Below are the setup for my 3 adapters:
    I've been trying for days to get these 2 nodes to talk to each other. I'd really appreciate your help in resolving this issue..I can't proceed with RAC installation unless I get these machines talking to each other..
    Thank you so much !
    @AJ

    1. "Note. The SCAN address should not really be defined in the hosts file. Instead is should be defined on the DNS to round-robin between 3 addresses on the same subnet as the public IPs. " You may specify as much IPs for SCAN as you wish but the first one only will be used.
    2. VIPs should be on the same NICs as physical IPs.
    3. Probably I missed something but I found nothing concerning 3 NICs.
    4. OL7 is supported starting from 11.2.0.4.
    5. It is possible to configure firewall instead of disabling it.
    6. It is necessary to configure OS, create user(s) and groups according to Installation Guide or use validator rpm.
    7. It is possible to configure disks with udev and not to use oracleasm.

  • I can not use mac book air with samsung galaxy 3 to transfer files. i download the  OS X mountain line version the latest one...how can i introduce them each other?

    i can not use mac book air with samsung galaxy 3 to transfer files. i download the  OS X 10.8.1 mountain line version the latest one...how can i introduce them each other?

    Thanks how do I get the latest version then? online its asking me to submit address details and all sort and I'm not keen to do that, I'm working away from the city I bought it in and there is no Apple Store near me yet?

  • Me and my wife share itunes acct for iour iphones and ipads how do we stop geting each others e-mails on our own devices

    me and my wife have iphones and ipads but we seam to get each others e-mails and would like to keep them seperate how do we do that when shareing one itunes acct

    According the this: http://www.apple.com/mobileme/transition.html, "After moving to iCloud, family member accounts are no longer linked to the master account."  You can share an iCloud calendar (see http://support.apple.com/kb/PH2690), but I don't think you will be able to share iCloud contacts unless you are signed into the same iCloud account on both phones.

  • After installing ios 6 to my iphone4 and my daughters iphone4s we now get each others text messages. How can we disconnect from each other so that I don't receive the text messages from her and her friends and she does not receive mine?

    After installing IOS6 on my iphone 4 and my daughters iphone 4s we have this wonderful connection that we would like to break.  We are now seeing/receiving each others text messages.  I love my daughter but I don't really want to get all of her text messages from her friends and I don't really want to read every response she sends.  Additionally, she can also see my text messages and there are times I really don't need for her to know everything that I am doing. 
    So It is time to cut the cord we need our own seperate texting.  I am not sure what we did to have this happen but how do we undo it?

    Get your Apple ID sort out.
    Only use the same Apple ID in Settings > iTunes & App Stores to share purchases, no where else.
    Here some tips, it was written for IOS 5 but it's still valid for iOS 6.
    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • We have 2 iphones 4 and one ipod touch and they all use the same apple address for purchases.  How do we stop getting each others texts?

    We are recieveing each others texts, it has only happened since we upgrated to iOS6.  We only get each others iMessages.

    You have two issues: 1. iPad is designed for single person use, not multiple users like a computer is, 2. Everyone trying to use this "single person" device uses the same Apple ID. As far as iMessage is concerned, this is the same person...how would it know differently?
    There is no solution to fix this. Even if everyone got their own Apple ID's, you're still trying to use a device, designed to be used by a single user, with multiple users. It simple is not gonna work, and if you manage to get it to work, it won't work very well.

  • X61T - How similar are models to each other for swapping parts purposes?

    I recently purchased an X61 Tablet at auction and am loving it. I got a great deal and it is exceeding my expectations already. (This isn't my first ThinkPad, though.)
    However, part of getting a great deal on it is that it isn't perfect. It was sold as surplus, and saw years of constant use before it made its way into my hands. There are a few things wrong with it that I've noticed, including:
    The center latch is loose. It locks, but it feels like someone who hadn't used a ThinkPad before pulled up on the top HARD a few times instead of using the switch.
    The slot where the pen goes doesn't have a way of ejecting the pen: the piece that grabs on to the pen's clip had broken off and was blocking the entire slot, so I removed it. The way the part broke means that there is no easy way to reattach it.
    I would like to get these fixed, eventually. Now for my actual question:
    How similar are the different models of X61T to each other?
    My computer is a 7764-CTO. I was thinking about just buying a 'for parts' X61T for these plastic pieces and to have some pieces to keep it alive for as long as possible. I'm assuming that the CTO ('configure-to-order') doesn't matter much and that any 7764 should work, but would a different model (e.g. 7767-XXX) be similar enough to buy for parts? I have reviewed the Hardware Maintenance Manual and they sometimes list different FRUs. However, it is difficult to tell to which FRU a part belongs (particularly the above parts). Moreover, I imagine that the FRUs may have different numbers but be functionally equivalent on occasion. 
    For practical purposes of cannibalizing parts from one X61T to another, how similar are the different models (776X) to each other? I would hate to buy a 'for parts' computer and have slight differences render it useless for my purposes. Thanks!

    X60T has a different (albeit swappable) LCD assembly, and utterly different palmrest and keyboard bezel. Couldn't tell you about the pen resting area since I've never looked into that...
    Cheers,
    George
    In daily use: R60F, R500F, T61, T410
    Collecting dust: T60
    Enjoying retirement: A31p, T42p,
    Non-ThinkPads: Panasonic CF-31 & CF-52, HP 8760W
    Starting Thursday, 08/14/2014 I'll be away from the forums until further notice. Please do NOT send private messages since I won't be able to read them. Thank you.

  • How to place elements among each other

    hi,
    how can i place checkboxes among each other, so that i have such design:
    checkbox 1 value 1
    checkbox 2 value 2
    checkbox 3 value 3
    and so on...
    i use following component:
    <h:selectManyCheckbox>
         <f:selectItems/>
    </h:selectManyCheckbox>i've tried also these ones, but it didn't help:
    <h:selectManyCheckbox>
    <h:outputText value="<br>" escape="false"/>
         <f:selectItems/>
    <h:outputText value="<br>" escape="false"/>
    </h:selectManyCheckbox>i always get all my checkboxes in one line:
    checkbox 1 value 1 checkbox 2 value 2 checkbox 3 value 3
    Maybe i can specify the style-attribute in <h:selectManyCheckbox> to force the line break?
    anybody how already solved such problem?

    ok, i did it you say, but now i get an exception:
    Could not find component 'tom' (calling findComponent on component 'imageForm:_id19:0:_id21')
    here the code:
    fill tomahawk component with selectedItems
    <h:panelGrid columns="1" styleClass="myFont">
         <h:column>
         <t:selectManyCheckbox value="#{dataBean.selectedItems}" id="tom" onclick="this.form.submit()" layout="spread">
              <f:selectItems value="#{dataBean.items}" id="selectTomaHawkItems"/>
         </t:selectManyCheckbox>
         </h:column>
    </h:panelGrid>place tomahawk-components in dataTable
    <h:panelGrid columns="1">
         <h:column>
              <h:dataTable value="#{dataBean.myList}" binding="#{MyDataBean.htmlDataTable}">
                 <h:column>
                      <t:checkbox index="#{MyDataBean.htmlDataTable.rowIndex}" for="tom"/>
                 </h:column>
             </h:dataTable>
         </h:column>
    </h:panelGrid>and MyDataBean has following lines:
    private HtmlDataTable htmlDataTable = new HtmlDataTable();
         public HtmlDataTable getHtmlDataTable() {
              return htmlDataTable;
         public void setHtmlDataTable(HtmlDataTable htmlDataTable) {
              this.htmlDataTable = htmlDataTable;
         public int getRowIndex() {
              return htmlDataTable.getRowIndex();
         }

  • Responsive design - how do boxes go under each other

    Hello,
    I want to make a responsive animation, I can rescale the whole animation, but in this case the text will be very small.
    I have 4 boxes next to each other, and I what I would like to do, when I resize the browser at a point the boxes would go under each other. Is there a way to do this?

    Hi, Mandi-
    So what you're talking about is a feature that many are calling "adaptive layout."  While Animate doesn't do this natively, you might want to check out the EdgeCommons library, which will allow you to set symbols for different widths based on media queries.
    http://www.edgedocks.com/edgecommons
    Hope this helps,
    -Elaine

  • Cant get 2 iPads to talk to each other with FaceTime.

    I have ipad2 , recently bought 10 yr old one too.  His iPad is registered to my apple I'd, I think he is too young to have own ID.  I have set up his iPad with a gmail address for FaceTime and I have another address for FaceTime on my iPad, so we can talk together over the summer when he is going to stay with family overseas.  Both email addresses are linked to my ID.  I've tried every which way I can but can't get FaceTime to work.  He is on my contact list, I am on his, but each time one of the iPads places a call we get call failed.  We have wi-fi, so that is not the problem.  All email addresses are verified, and the email address for video calls is different on each iPad.  Any one got any idea why it won't work?  I so want it to work and not have to resort to skype!

    Did you remove the Apple ID email address from one of the devices? Perhaps the devices are trying to reach each other at that same email address. Even if you associate another email address to the one device, you still have to remove the Apple ID address from that device or it will use that address as the one at which it can be reached for FaceTime.

Maybe you are looking for