
// Fail Liides3.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * Dialoog nime kysimiseks - swing.
 * @author Jaanus Poial
 * @version 0.3
 */
public class Liides3 {

   /** Peameetod tekitab liideseakna. */
   public static void main (String[] parameetrid) {
      new Liides_3();
   } // main lopp

} // Liides3 lopp

/** Konteiner dialoogi jaoks.
 */
class Liides_3 {

   JFrame tippAken;

   public Liides_3() { // konstruktor
      tippAken = new JFrame();
      tippAken.setSize (300, 150);
      tippAken.setTitle ("Kysimus");
      tippAken.addWindowListener (new WindowAdapter() {
         public void windowClosing (WindowEvent e) {
            e.getWindow().dispose();
         }
      });

      JLabel kysimus = new JLabel ("Mis su nimi on?");
      kysimus.setBackground (Color.gray);
      JTextField vastus = new JTextField (20); // laius
      vastus.setBackground (Color.lightGray);
      vastus.addActionListener (new ActionListener() {

         public void actionPerformed (ActionEvent e) {
            String nimi = ((JTextField)e.getSource()).getText();
            System.out.println ("Nimi on: " + nimi);
         } // actionPerformed lopp

      } // kuulariklassi lopp
      );

      JButton exitNupp = new JButton ("Minema");
      exitNupp.addActionListener (new ActionListener() {
         public void actionPerformed (ActionEvent e) {
            String nimi = ((JTextField)((Component)e.getSource()).getParent().
                  getComponent (1)).getText();
            System.out.println ("Nimi on: " + nimi);
            ((JFrame)((JPanel)((Component)e.getSource()).getParent()).getParent().getParent().getParent()).dispose();
         } // actionPerformed lopp
      } // kuulariklassi lopp
      );

      tippAken.getContentPane().setLayout (new GridLayout (3, 1));
      tippAken.getContentPane().add (kysimus);
      tippAken.getContentPane().add (vastus);
      tippAken.getContentPane().add (exitNupp);
      tippAken.setVisible (true);
   } // Liides_3 konstruktori lopp
   
   private static final long serialVersionUID = -8564370944529496313L;

} // Liides3 lopp

