Thread: A Java Question

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

    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
    Chappell Hill, Texas
    Posts
    2,332
    You're kidding, right?

    You'll need to something like this to fix it
    Code:
    // code here
    Mainframe assembler programmer by trade. C coder when I can.

  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
    587

    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, 04:12 PM
  5. A question for .. java!
    By McAuriel in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 11:16 AM