Outils pour utilisateurs

Outils du site


lang:java:gui:awt

Vue de la fenêtre AWT

Awt.java
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
@SuppressWarnings ("serial")
public class Awt extends Frame
{
  public static void main (final String[] args)
  {
    new Awt ();
  }
 
  public Awt ()
  {
    initialize ();
  }
 
  private void initialize ()
  {
    setTitle ("Bonjour");
 
    addWindowListener (new WindowAdapter ()
    {
      @Override
      public void windowClosing (final WindowEvent e)
      {
        dispose ();
      }
    });
 
    setLayout (new FlowLayout ()); // Le add place les composants les uns à la
                                   // suite des autres plutôt que les uns sur
                                   // les autres.
    add (new Label ("Label1", Label.CENTER));
    add (new Label ("Label2", Label.CENTER));
    Button button = new Button ("Fermer");
    button.addActionListener (new ActionListener ()
    {
      @Override
      public void actionPerformed (ActionEvent e)
      {
        dispose ();
      }
    });
    add (button);
 
    // setSize (280, 100);
    pack ();
 
    setVisible (true);
  }
}
lang/java/gui/awt.txt · Dernière modification : 2019/01/21 06:28 de root