Home • ECDL • Algoritmi • Java • Basi di dati • Seconda prova • Eccetera • Cerca nel sito

Eventi: Window... 2

Precedente
SUPERIORE
Successiva

Con la classe WindowAdapter sono resi disponibili, a scelta, tutti i metodi precedenti senza l'obbligo di implementarli tutti

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class WindowAdapterTest
{
   public static void main(String args[])
   {
      Frame f=new Frame();

      WA wa=new WA();
      f.addWindowListener(wa);
      f.addWindowStateListener(wa);
      f.addWindowFocusListener(wa);

      f.setTitle("Prova WindowAdapter!"); 
      f.setSize(400, 400);
      f.setVisible(true); 
   }
}

class WA extends WindowAdapter
{
   public void windowActivated(WindowEvent we)   { System.out.println("Activated");   }
   public void windowDeactivated(WindowEvent we) { System.out.println("Deactivated"); }
   public void windowOpened(WindowEvent we)      { System.out.println("Opened");      }
   public void windowClosing(WindowEvent we)     { System.out.println("Closing");     }
   public void windowClosed(WindowEvent we)      { System.out.println("Closed");      }
   public void windowIconified(WindowEvent we)   { System.out.println("Iconified");   }
   public void windowDeiconified(WindowEvent we) { System.out.println("Deiconified"); }
   public void windowGainedFocus(WindowEvent we) { System.out.println("GainedFocus"); }
   public void windowLostFocus(WindowEvent we)   { System.out.println("LostFocus");   }
   public void windowStateChanged(WindowEvent we){ System.out.println("StateChanged");}
}

Le parti in corsivo sono facoltative...

Per semplificare è possibile utilizzare una classe interna

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class WindowAdapterTest extends Frame
{
    public WindowAdapterTest()
    {
       WA wa=new WA();
       this.addWindowListener(wa);
       this.addWindowStateListener(wa);
       this.addWindowFocusListener(wa);

       this.setTitle("Prova WindowAdapter!"); 
       this.setSize(400, 400);
       this.setVisible(true); 
    }
    public static void main(String args[])
    {
       WindowAdapterTest wat=new WindowAdapterTest();
    }

    class WA extends WindowAdapter
    {
       public void windowActivated(WindowEvent we)   { System.out.println("Activated" );   }
       public void windowDeactivated(WindowEvent we) { System.out.println("Deactivated" ); }
       public void windowOpened(WindowEvent we)      { System.out.println("Opened" );      }
       public void windowClosing(WindowEvent we)     { System.out.println("Closing" );     }
       public void windowClosed(WindowEvent we)      { System.out.println("Closed" );      }
       public void windowIconified(WindowEvent we)   { System.out.println("Iconified" );   }
       public void windowDeiconified(WindowEvent we) { System.out.println("Deiconified" ); }
       public void windowGainedFocus(WindowEvent we) { System.out.println("GainedFocus" ); }
       public void windowLostFocus(WindowEvent we)   { System.out.println("LostFocus" );   }
       public void windowStateChanged(WindowEvent we){ System.out.println("StateChanged"); }
    }

}

Eventi: Window... 2 - ApPuNtIdIuNiNfOrMaTiCo

Home • ECDL • Algoritmi • Java • Basi di dati • Seconda prova • Eccetera • Cerca nel sito

Precedente
SUPERIORE
Successiva