import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public static void main(String[] args) {
// أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
JFrame frame = new JFrame("WindowListener Demo");
// هنا قلنا أنه كلما تفاعل المستخدم مع النافذة سيتم إظهار الحدث الذي فعله كرسالة
frame.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent e) {
JOptionPane.showMessageDialog(frame, "Event: Window Opened");
public void windowClosing(WindowEvent e) {
JOptionPane.showMessageDialog(frame, "Event: Window Closing");
public void windowClosed(WindowEvent e) {
public void windowIconified(WindowEvent e) {
JOptionPane.showMessageDialog(null, "Event: Window Iconified");
public void windowDeiconified(WindowEvent e) {
JOptionPane.showMessageDialog(null, "Event: Window Deiconified");
public void windowActivated(WindowEvent e) {
public void windowDeactivated(WindowEvent e) {
frame.setSize(300, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 300
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setVisible(true); // هنا جعلنا النافذة مرئية
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class Main {
public static void main(String[] args) {
// أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
JFrame frame = new JFrame("WindowListener Demo");
// هنا قلنا أنه كلما تفاعل المستخدم مع النافذة سيتم إظهار الحدث الذي فعله كرسالة
frame.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
JOptionPane.showMessageDialog(frame, "Event: Window Opened");
}
@Override
public void windowClosing(WindowEvent e) {
JOptionPane.showMessageDialog(frame, "Event: Window Closing");
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
JOptionPane.showMessageDialog(null, "Event: Window Iconified");
}
@Override
public void windowDeiconified(WindowEvent e) {
JOptionPane.showMessageDialog(null, "Event: Window Deiconified");
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
});
frame.setSize(300, 300); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 300
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setVisible(true); // هنا جعلنا النافذة مرئية
}
}