A Java Question

This is a discussion on A Java Question within the Tech Board forums, part of the Community Boards category; Hi all, I have a question in Java. I have something like this. 1st program: Code: Class A extends javax.swing.JFrame{ ...

  1. #1
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    501

    A Java Question

    Hi all,
    I have a question in Java.
    I have something like this.
    1st program:
    Code:
    Class A extends javax.swing.JFrame{
    //Code here
    new B().setVisible(true);
    }
    2nd Program:
    Code:
    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..
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    You're kidding, right?

    You'll need to something like this to fix it
    Code:
    // code here
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    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:
    Code:
    Class A extends javax.swing.JFrame{
    setDefaultCloseOperation(WindowConstants.DisposeOnClose);
    new B().setVisible(true);
    }
    But that might not be exactly how its typed. If you have netbeans the code copletion should help.

  4. #4
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    501

    Thumbs up

    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
    Code:
    {
    setDefaultCloseOperation(WindowConstants.DisposeOnClose);
    }
    it was
    Code:
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    by default for the code generated by netbeans.

    Thanks a lot mike_g.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mats, the java answers
    By Jaqui in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-22-2008, 02:12 AM
  2. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  3. Windows GDI vs. Java Graphics
    By Perspective in forum Windows Programming
    Replies: 7
    Last Post: 05-07-2007, 10:05 AM
  4. How to use Java with C++
    By Arrow Mk 84 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2003, 03:12 PM
  5. A question for .. java!
    By McAuriel in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 10:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21