I am relatively new at java and I am making a HangMan Game but I am facing a problem right now.In particular, I want to close the frame of the program to open a new one when someone finds the word but since my class there extends JPanel dispose() isn't an available solution. So, what should I do to close this frame? ( bare in mind that its object is defined at another class, the one that calls that specific one.) Here is part of my code: ( please forgive me for displaying so many lines ) I just want to know how I can close this window without exiting the whole program, Thanks for your time :) )
EDIT: Thanks guys, I really learned a lot through this '' comment section''. I am grateful for your quick responds and I hope that in the future i will not ask such a silly question again:) PS: I actually used the CardLayout to solve my problem. I don't really see thought how this question is similar to '' How to programmatically close a JFrame '' since in this one I can't use the dispose method because i am extending a JPanel.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//import java.io.File;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class Game extends JPanel implements Runnable{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
this.setBackGround(Color.BLACK);
}
public void run()
{
}
}