Monday, 25 July 2016

java - How to close a JFrame while opening another JFrame?

I have a frame (main). There are two buttons: Items and Sale.



When I click button Items it opens a frame (Items)
and I want to, when I click on button Sale, it should close the Items and open Sale.




This is Items frame:



public class Items extends JFrame {

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Items frame = new Items();
frame.setVisible(true);

} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}


UPDATE :- here is my sale class




public class Sale extends JFrame {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Sale frame = new Sale();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();

}
}
});
}
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...