Skip to Content
0
Former Member
Oct 27, 2006 at 01:38 PM

Close the current UI and open another one

12 Views

Hello everyone,

I've got the following code and I want to close the current window and open another one. When i use "System.exit(1);" it closes everything when I use "this.dispose()" it doesn't close anything what could I try to get this to work? any suggestions?

the code is:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

//public class Equip_or_Job implements ActionListener {

public class Equip_or_Job extends Frame implements ActionListener {

JFrame dFrame;

JPanel jePanel;

JButton choice;

JComboBox jeqid = new JComboBox();

public Equip_or_Job() {

//Create and set up the window.

dFrame = new JFrame("Work with Jobid or Equipid");

dFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the panel.

jePanel = new JPanel(new GridLayout(2, 1));

dFrame.getContentPane().setLayout(new BorderLayout());

//Add the widgets.

addWidgets();

//Set the default button.

dFrame.getRootPane().setDefaultButton(choice);

//Add the panel to the window.

dFrame.getContentPane().add(jePanel, BorderLayout.CENTER);

//Display the window.

dFrame.pack();

dFrame.setVisible(true);

}

/**

  • Create and add the widgets.

*/

private void addWidgets() {

//Create widgets.

jeqid.addItem("Chose by Job");

jeqid.addItem("Chose by Equipment");

choice = new JButton("Chose");

//Listen to events from the Convert button.

choice.addActionListener(this);

jePanel.add(jeqid);

jePanel.add(choice);

}

public void actionPerformed(ActionEvent event) {

String sel = (String) jeqid.getSelectedItem();

if("Chose by Job".equals(sel)){

InsertNewDates inj = new InsertNewDates();

//System.exit(1);

dispose();

}

else if("Chose by Equipment".equals(sel)){

InsertNewDates ineq = new InsertNewDates();

//System.exit(1);

dispose();

}

}

/**

  • Create the GUI and show it. For thread safety,

  • this method should be invoked from the

  • event-dispatching thread.

*/

private static void createAndShowGUI() {

//Make sure we have nice window decorations.

try {

UIManager.setLookAndFeel(

UIManager.getCrossPlatformLookAndFeelClassName());

}

catch (Exception e) { }

Equip_or_Job eorj = new Equip_or_Job();

}

public static void main(String[] args) {

//Schedule a job for the event-dispatching thread:

//creating and showing this application's GUI.

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

}

thanks in advance :o)