This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear Friends,
In my application, I have 3 Frames. like A.java, B.java, and C.java
I have to close C.java Frame using a button click from A.java.
When i am trying to close C Frame from A Frame,
it is saying java.nullpointer exception.
for eg : I have 3 Frame classes like A, B and C.
B Frame will be opened using a button click from A Frame.
C Frame will be opened using a button click from B Frame.
I have to close C Frame using a Button click from A Frame.
I am new to java. Please help me.
Thanks in advance.
Looking forward to hearing from
My A.java, B.java and C.java programs are like this.
All the Frames are opening fine. only problem is while closing C Frame from A Frame
=======================
A.Java
=======================
import java.awt.*;
import java.awt.event.*;
public class A extends Frame implements ActionListener
{
B b;
C c;
Button showBChild, closeCChild;
A()
{
setLayout(new FlowLayout());
showBChild = new Button("Show B Frame");
add(showBChild);
showBChild.addActionListener(this);
closeCChild = new Button("Close C Frame");
add(closeCChild);
closeCChild.addActionListener(this);
setVisible(true);
setSize(300,300);
show();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == showBChild) {
b = new B();
}
if(ae.getSource() == closeCChild) {
c.dispose();
}
}
public static void main(String args[]) {
new A();
}
}
=======================
B.Java
=======================
import java.awt.*;
import java.awt.event.*;
public class B extends Frame implements ActionListener
{
C c;
Button showChild;
B()
{
setLayout(new FlowLayout());
showChild = new Button("Show C Frame");
add(showChild);
showChild.addActionListener(this);
setVisible(true);
setSize(300,300);
show();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == showChild) {
c = new C();
}
}
public static void main(String args[])
{
new B();
}
}
=======================
C.Java
=======================
import java.awt.*;
import java.awt.event.*;
public class C extends Frame
{
C()
{
setLayout(new FlowLayout());
setVisible(true);
setSize(300,300);
show();
}
}
=========================
Looking forward to hearing from.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Here's a hint...
Inside class A, make this change:

Now, frame c will be disposed of, if frame b has created one. Otherwise you'll still throw an exception.
Was this enough of a hint?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear Mr.Schreckmann,
Thank you very much.
Your reply helped me alot.
Millions of Thanks to you.
Yours
Rajesh

Originally posted by Dirk Schreckmann:
Here's a hint...
Inside class A, make this change:

Now, frame c will be disposed of, if frame b has created one. Otherwise you'll still throw an exception.
Was this enough of a hint?
 
 
subject: Exception
 
Similar Threads
Reset layout manager
java.awt BorderLayout and FlowLayout
validating awt textfields
GUI'S
Displaying Photo's with Frame GUI