sujitopics
Programmer
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 you again.
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 you again.