Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error

 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
please help me.
I have to close B_Frame (Child frame) from A_Frame (Parent) with a button click.
In A_Frame.java (Parent Frame) I used like this :
public void closeChildFrame()
{
System.out.println("close()");
B_Frame.hide();
B_Frame.dispose();
}
Compilation error :
non-static method hide() cannot be referenced from a static context B_Frame.hide();
^
non-static method dispose() cannot be referenced from a static context
B_Frame.dispose();

please help me.
your kind cooperation would be greatly appreciated.
Thanks in advance.
 
John Utting
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh,
You are trying to invoke the instance methods
hide() and dispose() using the class reference (B_Frame) rather than using an object of the class.
Try the following:
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
When youi call the closeChildFrame() method pass a reference to an object of type B_Frame.
Hope this helps.
 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear John,
I am deeply grateful to you for your kind cooperation.
I made changes in closeChildFrame method. It is ok. but it is giving problem when i call that method.
please see this one.
Thank you very much.
Yours
Rajesh
jMenuItem_close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeChildFrame();
}
});
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
error : cannot be applied to closeChildFrame();
please help me, what changes shall i do to avoid this error.
I am new to java.
Thanks once again.
Originally posted by John Utting:
Rajesh,
You are trying to invoke the instance methods
hide() and dispose() using the class reference (B_Frame) rather than using an object of the class.
Try the following:
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
When youi call the closeChildFrame() method pass a reference to an object of type B_Frame.
Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic