如何关闭构造函数框架


public class RainfallStudy extends JFrame{
/**
* Declare global variables
*/
int x = 20, y = 567; //starting location for the title 
int xSpeed = 20, ySpeed = 20; // the speed for x and y directions
int delay = 20; // to slow down my title 
ImageIcon BackGnd, pic; // variables for the pictures
/**
* Constructor to build the frame
*/
public RainfallStudy() {
// this builds a window with a title
super("Weather Report");
setSize(1000,567);
//loading the picture files
BackGnd = new ImageIcon ("weatherBack.png");
pic = new ImageIcon ("weatherIcon.png");
setResizable(false);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

这就是我制作框架的方式,然后我在public void paint(Graphics g)中制作动画。

现在,在我使用new RainfallStudy();在主窗口中调用它之后,动画完成后窗口保持打开,我如何手动关闭它?

在RainfallStudy实例上调用dispose或setVisible是否有效?例如:

RainfallStudy rs = new RainfallStudy();
rs.setVisible(false);

最新更新