A Java Question [Archive] - C Board

PDA

View Full Version : A Java Question


stevesmithx
04-01-2008, 05:49 AM
Hi all,
I have a question in Java.
I have something like this.
1st program:

Class A extends javax.swing.JFrame{
//Code here
new B().setVisible(true);
}

2nd Program:

Class B extends javax.swing.JFrame{
//Code here

}

The problem is when I run the 1st program and close the Window of second program(which is called as new B() in pgm 1) , both windows close .
However I want the 1st window to remain there.
How can i do this?
please help..

Dino
04-01-2008, 06:10 AM
You're kidding, right?

You'll need to something like this to fix it

// code here

mike_g
04-01-2008, 06:12 AM
You might want to have a look at setting the default close operation for your window. Then set window A's close operation to dispose on close. If i remember correctly its something like:
Class A extends javax.swing.JFrame{
setDefaultCloseOperation(WindowConstants.DisposeOn Close);
new B().setVisible(true);
}
But that might not be exactly how its typed. If you have netbeans the code copletion should help.

stevesmithx
04-02-2008, 12:51 PM
ou might want to have a look at setting the default close operation for your window. Then set window A's close operation to dispose on close. If i remember correctly its something like:
Code:

Class A extends javax.swing.JFrame{
setDefaultCloseOperation(WindowConstants.DisposeOn Close);
new B().setVisible(true);
}

But that might not be exactly how its typed. If you have netbeans the code copletion should help.


That was exactly the mistake I made.
instead of

{
setDefaultCloseOperation(WindowConstants.DisposeOn Close);
}

it was


setDefaultCloseOperation(WindowConstants.EXIT_ON_C LOSE);


by default for the code generated by netbeans.

Thanks a lot mike_g.