how can I trigger anything outside the method ???
like carry the boolean a outside
public void windowClosing(WindowEvent arg0) {
System.out.println("Window Closing");
a=true; // cant refer to non final variable a inside an inner class defined in a different method
I want to use "a" in while loop for instance
I cant get event out of that method down,it's frustrating
here's the whole program:
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
public class WinLsnrExp extends JFrame {
//private boolean a=true;
public WinLsnrExp() {
setTitle("Window listener Example : ");
setSize(150, 150);
}
public static void main(String[] args) {
//int xI,yI;
//double xD,yD;
boolean a = false;
while (a){
/* for (int i=0;i<100;i++) {
WinLsnrExp wle = new WinLsnrExp();
wle.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
wle.setLocation((int)(Math.random()*1000),(int)(Math.random()*1000));
wle.setVisible(true);
}
}}
//xD=1000*Math.random();
//int xI = (int)xD;
*/
System.out.println(Math.random());
WinLsnrExp wle = new WinLsnrExp();
wle.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
wle.setLocation((int)(Math.random()*1000),(int)(Math.random()*1000));
wle.setVisible(true);
wle.addWindowListener(new WindowListener() {
public void windowClosed(WindowEvent arg0) {
System.out.println("Window close event occur");
}
public void windowActivated(WindowEvent arg0) {
System.out.println("Window Activated");
}
public void windowClosing(WindowEvent arg0) {
System.out.println("Window Closing");
a=true; // cant refer to non final variable a inside an inner class defined in a different method
}
public void windowDeactivated(WindowEvent arg0) {
System.out.println("Window Deactivated");
}
public void windowDeiconified(WindowEvent arg0) {
System.out.println("Window Deiconified");
}
public void windowIconified(WindowEvent arg0) {
System.out.println("Window Iconified");
}
public void windowOpened(WindowEvent arg0) {
System.out.println("Window Opened");
}
});
}
}
}