JFrame窗口未关闭

  • 本文关键字:窗口 JFrame java
  • 更新时间 :
  • 英文 :


所以我试图制作一个测试应用程序,但在下面出现了这个错误

我想关闭JFrame窗口,所以我尝试了setVisible(false(;关闭窗口,如果有人点击后退按钮,但它不起作用,帮助我,因为我是新的。我甚至试过Jframe.dispose((;和其他方法我不知道我犯了什么错误,如果你帮我,请

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Login extends JFrame implements ActionListener {
JButton Rules,Back;

Login() {
getContentPane().setBackground(Color.white);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icon/login.jpeg"));//<-- to pick images from directory
setLayout(null);
JLabel image = new JLabel(i1);
JLabel heading = new JLabel("Quiz Bazzi");
heading.setBounds(750,50,300,50);
heading.setFont(new Font("Mongolian Baiti",Font.BOLD,42));
heading.setForeground(Color.ORANGE);
add(heading);
JLabel name = new JLabel("Enter Your Name");
name.setBounds(785,150,350,20);
name.setFont(new Font("Mongolian Baiti",Font.BOLD,18));
name.setForeground(Color.black);
add(name);
JTextField tfname = new JTextField();
tfname.setBounds(715,180,300,25);
tfname.setFont(new Font("Times New Roman",Font.BOLD,18));
tfname.setForeground(Color.black);
add(tfname);
Rules = new JButton("Rules");
Rules.setBounds(715,220,120,25);
Rules.setBackground(Color.black);
Rules.setForeground(Color.white);
add(Rules);
Back = new JButton("Back");
Back.setBounds(895,220,120,25);
Back.setBackground(Color.black);
Back.setForeground(Color.white);
add(Back);
image.setBounds(0,0,500,400);
add(image);
setSize(1200,439);
setLocation(180,100);
setVisible(true);
}  
public void actionPerformed(ActionEvent e){
if(e.getSource() == Rules){
setVisible(true);
} else if (e.getSource() == Back) {
setVisible(false);
}

}
public static void main(String[] args) {
new Login();
}
}

你知道它的用途吗:

JFrame.dispose();

这正是你所需要的:(

最新更新