Results 1 to 4 of 4

Thread: dispose

  1. #1
    simontkk2005 is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default dispose

    hi guy.

    i have few classes with GUI. Like class a ,class b, class c.

    if now my program execute in class a and display class a , while class c is display there too.

    So if there any possible for me to dispose class C form when my program execute in class a.??




    class CountdownTimerListener implements ActionListener {

    public void actionPerformed(ActionEvent e) {

    if (--timeRemaining > 0) {

    jlbtime.setText(String.valueOf(timeRemaining));

    } else{

    jlbtime.setText("Time's up!");
    System.out.print("time put");

    countdownTimer.stop();
    //System.exit(0);
    //Administrator.EXIT_ON_CLOSE(0);
    //dispose(Administrator());
    // Administrator.DISPOSE_ON_CLOSE
    Login frame = new Login();

    frame.setVisible(true);
    frame.setTitle("WELCOME TO STOCK KEEPS PROGRAM");
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(400,280);

    }

    }

    }

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    Java Code:
    //System.exit(0);
    //Administrator.EXIT_ON_CLOSE(0);
    //dispose(Administrator());
    // Administrator.DISPOSE_ON_CLOSE
    
    Login frame = new Login();
    frame.setVisible(true);
    frame.setTitle("WELCOME TO STOCK KEEPS PROGRAM");
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(400,280);
    The code lacks the global variables that would solve the problem.
    The main application class needs global variables for the various frames.
    Let's call the window to close as oldOne and the window to be created as newOne.
    Then the code above is something like:
    Java Code:
        oldOne.dispose();
        newOne = new Login();
        newOne.showYourself();
    where the showYourself() method does everything to make the window appear.

  3. #3
    simontkk2005 is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default

    hi zweibieren. thank you for the solution.

    but i try myoldpost.dispose(); -----

    the error :non-static method dispose() cannot be referenced from a static context.

    do you know what happen actually ,or i need to import somethings to make it run.

    thanks.

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    Please read the tutorials.
    Especially the one on Objects and Classes.


    If you get "non-static method dispose() cannot be referenced from a static context"
    for myoldpost.dispose(), then myoldpost is not an object.
    When you create a window, you create an object.
    Assign that object to myoldpost. Then you can dispose() it later.

Similar Threads

  1. dispose() does not work here
    By arunkumarinfo in forum NetBeans
    Replies: 5
    Last Post: 12-28-2013, 05:42 PM
  2. [SOLVED] Not dispose my JPanel
    By Eranga in forum Advanced Java
    Replies: 3
    Last Post: 11-14-2010, 03:02 PM
  3. dispose all using Vector ?
    By sysout in forum New To Java
    Replies: 10
    Last Post: 08-31-2009, 04:51 PM
  4. [SOLVED] how do I dispose a view?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-07-2008, 06:15 PM
  5. How to dispose tooltip.
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-22-2008, 07:06 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
  •