Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 77
  1. #41
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    .which reference i have to pass
    Which class contains the method you want to call? That is the reference you need to pass to the class where you want to call its method.
    If you don't understand my response, don't ignore it, ask a question.

  2. #42
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    Main class contains the method,and display method i want to call from there and also i have called it using instance of Main class that is "o" and pass "p1" as a refrence to it but nothing happens.

  3. #43
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    also i have called it using instance of Main class that is "o"
    Are you saying that there are two instances of the Main class? I thought you only wanted to have one instance of the Main class.
    Main class contains the method,
    Then you need to pass a reference to the Main class to the other class where you want the code to call a method in the Main class. In the methods of the Main class, the this variable contains a reference to the current instance of the Main class. You need to pass that reference (this) to where you want to call the Main class's display() method.
    If you don't understand my response, don't ignore it, ask a question.

  4. #44
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    yes i want only one instance of main class not the other one "o",i have made it to call the display() from main in New2 panel and passed the refrence "p1" to display() method.
    is there any other way to call the method without making instance of main class.

  5. #45
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    way to call the method without making instance of main class.
    Yes, pass a reference to the ONE instance of the Main class to the New2 class where you want to use it.
    Where is the instance of that New2 class created?
    Can a reference to the ONE instance of the Main class be passed to the constructor of the New2 class where you want to use it? Have the constructor save the reference so that other methods in that New2 class can use it.
    If you don't understand my response, don't ignore it, ask a question.

  6. #46
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    can you code it what are you want to do,i cant understand

    i just want that on the jframe window the button "label1" will be displaced by Label Panel on the same jframe.

  7. #47
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    Where is the code that creates an instance of the New2 class?
    Add a parameter to that statement that passes a reference to the Main class to the New2 class's constructor.
    .. = new New2(<REFERENCE TO MAIN CLASS HERE>);
    The constructor:
    public New2(Main refToMain) {
    // here save that reference so later it can be used to call the display() method in Main
    If you don't understand my response, don't ignore it, ask a question.

  8. #48
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    no New2 class instance has been created anywhere,

  9. #49
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    In post#44 you said:
    made it to call the display() from main in New2 panel
    I thought that was the class that had a method where you wanted to call the Main class's display() method.
    If that is not the class, then replace New2 with the class where you want to do the call.
    If you don't understand my response, don't ignore it, ask a question.

  10. #50
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    i am so sorry friend but i can't understand what are you saying
    if you have seen my code .
    then just give me code or with an example tell me what i have to do so that when i will click on "label1" button then Label panel will be displayed at the place of "label1" button.

  11. #51
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    Can you answer these questions?
    1) What is the name of the class and the name of the method in that class where you want to call the Main class's display() method?
    2) Where is an instance of that class created?

    You talk about variables that are inside some class without giving the name of the class they are in. It's important when talking about code to be specific to avoid confusion.
    If you don't understand my response, don't ignore it, ask a question.

  12. #52
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    This is confusing. You said:
    no New2 class instance has been created anywhere,
    Look at posts #24 and #26. There is a New2 class defined there????
    If you don't understand my response, don't ignore it, ask a question.

  13. #53
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    name of the class- New2
    name of the method - b1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {

    its instance is created in main class under method-

    new1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {


    i want that when i will click on label1 button ,label pane will be added at the place of that button

    Thanks

  14. #54
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    its instance is created in main class under method-
    Use the New2 class's constructor to pass a reference to the Main class to the instance of the New2 class.
    Find where I told you how to use the this variable that contains a reference to the method that is executing in a class.
    Then use that reference to call the Main class's display() method.
    If you don't understand my response, don't ignore it, ask a question.

  15. #55
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    now what or which refrence i have to put here "REFERENCE TO MAIN CLASS HERE"

    Java Code:
     .. = new New2(<REFERENCE TO MAIN CLASS HERE>);
    and also what i have to save here in the constructor
    Java Code:
     public New2(Main refToMain) {
    // here save that reference so later it can be used to call the display() method in Main

    CAN YOU PLEASE ELABORATE

  16. #56
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    now what or which refrence i have to put here "REFERENCE TO MAIN CLASS HERE"
    If you'd read my previous post about the this variable, you would have the answer for that.
    Research the this variable.

    save that reference so later it can be used to call the display() method in Main
    Define a variable of type Main as a class instance variable:
    Main refToMain;
    In the constructor, assign that variable the value passed to the constructor:
    this.refToMain = refToMain; // save
    later in the code when you want to call a method in Main:
    refToMain.aMethodInMain(); // call a method in Main
    If you don't understand my response, don't ignore it, ask a question.

  17. #57
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: can't navigate from child panel to main panel

    (nitpick: 'this' is not a variable but a keyword)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  18. #58
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    this is a reference to the current object
    It's useful to think of this as a R/O variable because it contains a value. It is definitely a keyword.
    If you don't understand my response, don't ignore it, ask a question.

  19. #59
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: can't navigate from child panel to main panel

    You are right, but you said "research" and a web search for 'java this keyword' will probably return more relevant hits than 'java this variable'. Savvy?

    (always wanted to say that!)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  20. #60
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    Yes, of course, but what does Google know?
    If you don't understand my response, don't ignore it, ask a question.

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 04-03-2011, 12:35 PM
  2. panel on a panel not visible
    By warchieflll in forum Advanced Java
    Replies: 2
    Last Post: 01-29-2011, 08:29 PM
  3. Displaying panels inside a main panel
    By Sneaky Fox in forum AWT / Swing
    Replies: 4
    Last Post: 01-21-2011, 04:12 PM
  4. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 08:43 PM
  5. How to add more components to main panel
    By aneesahamedaa in forum AWT / Swing
    Replies: 4
    Last Post: 08-21-2008, 06:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •