Instanciating an application in an application


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Instanciating an application in an application

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    3

    Red face Instanciating an application in an application

    Hi,

    I'm having trouble with java applications. I'm hoping that some-one can help me with my program.
    I read in the beginning that stupid questions are OK here, so I'm realy at ease to ask this question now ...

    I know that java is multi-threading and multi-tasking and I've had a basic java training, so I can understand some of the more difficult things in java. I want to make an AWT application with a menubar. In that menubar is a button with "NEW" as label. The user should be able to instanciate this application again, lets say open it again. I've got it working like this:

    import java.awt.*;
    import java.awt.event.*;

    public class Application1 extends Frame{
    // declarations go here
    public static void main(String[] args){
    new Application1();
    }
    public Application1(){
    // stuff in the program goes here
    }
    // other stuf goes here, like handlers for the menu
    }
    // end of program

    Now I've got an windowhandler so when you click on the close button that the window will close.
    And then I've got the "NEW" button like this:

    private class menuhandler implements ActionListener{
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==nieuwItem) new Sudoku1();
    }
    }
    // end of java code

    So the program makes another instance of the CLASS, and I can do this multiple times while they all interact with the user seperately. So I would say its all OK. But when I press the close button, then it closes all of the windows ...
    I also get only one dos-window, while I need to have as many as there are instances.

    Can some-one save me from my misery? And explain to me what I did wrong and what I did do with this instruction (this instruction must do something, but its not what I hoped). And maybe give the solution to my problem as well.

    Thanks to all who helps me ... Bye !
    Newbie in JAVA applets
    Newbie in JAVA AWT applications
    SWING too hard, haven't realy tried

  2. #2
    Join Date
    Mar 2006
    Posts
    28
    every application can only be instanciated once, because it only has one 'main' method, that's why you also have one dos window too

    you can however use JInternalFrame or JTabbedPane if you want more windows
    or you can just create multiple JFrame objects

  3. #3
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    3

    Lightbulb

    Thanks for replying IceCubeC,

    But I have apsolutely no experience with SWING. Is there a way to do this with AWT? I thought about counting the amount of windows in an array or vector, and thus keeping track of the windows. When the user closes an particular window than the application could maybe look up in what window the close button is pressed and delete that one out of the vector and close that window. But I don't realy know how to program this ... if it is possible.

    Or is it possible to open (instantiate) a different application by klicking on a button in an application? And how can I do this if it is possible.
    I would also want to have popups in my application, and with AWT it isn't realy possible. But with this way it could be possible, just open another application ... ... ??

    Let me know ... Thanks anyway!
    Newbie in JAVA applets
    Newbie in JAVA AWT applications
    SWING too hard, haven't realy tried

  4. #4
    Join Date
    Mar 2006
    Posts
    28
    if you use a frame it's hard to deny the fact that eventually you'll have to use swing to add interface components

    what's the meaning of your app anyway?

  5. #5
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    3
    hi IceCubeC,

    The usage of this application is not very important or life-saving . It's just for fun, I was trying to make a game.

    I already taught myself how to use cardlayout to make this game. The main idea after this is to keep my knowledge of java up to date. The previous semester I had an exam of java, but I like java so much that I don't want to let it go.

    But swing is another matter ... when we had to make an application for the first time, we started in AWT and when it was finished we could make a swing application. The AWT application was fairly easy, but when I started at the SWING application I was confused. Everything had another name, almost all of the things started with a "J", ... And we didn't get any information or lesson or exam about it, we had to look it up, use it one time and that was it. I didn't finish that application either. It looked so complicated!

    So this means that i should get rid of my fears and get cracking at that swing application anyways ... if i want to finish this game?

    May the force be with me ...
    Newbie in JAVA applets
    Newbie in JAVA AWT applications
    SWING too hard, haven't realy tried

Similar Threads

  1. Replies: 1
    Last Post: 12-04-2002, 03:04 PM
  2. Replies: 1
    Last Post: 12-01-2002, 07:42 AM
  3. Replies: 0
    Last Post: 11-26-2002, 12:09 AM
  4. Replies: 0
    Last Post: 11-26-2002, 12:05 AM
  5. Inventory Management Application Using VB
    By Krishna in forum vb.announcements
    Replies: 0
    Last Post: 11-26-2002, 12:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center