so i was trying to make a quiz application but i got this error below
I Want to close the JFrame window so i tried setVisible(false); to close window if someone click back button but it is not working help me as im new. i even tried Jframe.dispose(); and other methods i dont what error i have made if you help me pls
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();
}
}
Do you know what it the purpose of:
JFrame.dispose();
?
It is exactly what you need:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.