Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Java Child - Parent ? Please help im lost !

Mr_SmithMr_Smith Member Posts: 33
[b][red]This message was edited by Mr_Smith at 2002-10-21 9:2:50[/red][/b][hr]
Hi i have a class say Engine and it has a Parent Car how can i use a callback to tell the Car the Engine is broken rather than asking it every 5 seconds?

Ive tried everything and just cant understand callbacks in java.


Comments

  • chamsterchamster Member Posts: 662
    [b][red]This message was edited by chamster at 2002-10-21 15:51:0[/red][/b][hr]
    I'm not sure if it's what you're looking for but you might send the parent as a pointer to the object. Something like:

    [code]
    class Child
    {
    private Parent parent;

    public Child (Parent p)
    {
    this.parent = p;
    }
    }
    [/code]

    Now, if you have a method [blue]notify ()[/blue] in Parent class you only need to go [blue]this.parent.notify ();[/blue] form Child-class.



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com



  • Mr_SmithMr_Smith Member Posts: 33
    [b][red]This message was edited by Mr_Smith at 2002-10-22 3:15:29[/red][/b][hr]
    Help class parent not found so no work
  • chamsterchamster Member Posts: 662
    Great. Let me know when you're done if it really was what you were looking for.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Mr_SmithMr_Smith Member Posts: 33
    help class Parent not found
  • chamsterchamster Member Posts: 662
    Have you compiled both Parent and Child? Meaning in your case have you compiled Engine and Car?

    Make sure that the .class-files are in your directory (Car.class and Engine.class must be in the directory from which you execute the program).

    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Mr_SmithMr_Smith Member Posts: 33
    [b][red]This message was edited by Mr_Smith at 2002-10-23 6:47:35[/red][/b][hr]
    Yep its all fine and is amazing thx

    bit of confusion back there as i thought u meant there was an actual parent class maybe that acted as a pointer, but i understand how it works now.
  • Justin BibJustin Bib USAMember Posts: 0

    _________ [ http://forcoder.org ] free ebooks and video tutorials about // Java, Swift, C, Objective-C, Perl, C++, Python, Visual Basic .NET, C#, Delphi, JavaScript, Go, Ruby, R, MATLAB, Scratch, Assembly, PHP, Visual Basic, PL/SQL ABAP, FoxPro, Erlang, Logo, Scala, Alice, Hack, Julia, Rust, LabVIEW, VBScript, Ada, SAS, Apex, ML, Fortran, COBOL, Clojure, F#, D, Lisp, Lua, Bash, Dart, Kotlin, Crystal, Transact-SQL, Prolog, Scheme, Awk // _____

Sign In or Register to comment.