cancel
Showing results for 
Search instead for 
Did you mean: 

Close the current UI and open another one

Former Member
0 Kudos

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 🐵

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

I'm not exactly sure what you want to do, but...:

dFrame.setVisible(false) hides the current Frame and the application is still running

Best reagrds, Marco