//DEMO DE VENTANA CON ALGUNOS COMPONENTES
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
// Prototipo de una aplicacion de ventana
// 1.- Se crea la clase que extienda a la clase Frame, JFrame o Window
public class Ventana extends JFrame
{
// SE CREAN Y SE INICIALIZAN LOS COMPONENTES
JButton Boton = new JButton("OK");
JLabel Etiqueta = new JLabel("INICIO");
JTextField CAMPOTEXTO = new JTextField();
public Ventana ()
{
this.getContentPane().setLayout(null); // Contenedor nulo
this.setTitle("TITULO"); // Titulo de la ventana
this.setResizable(false); // No es redimensionable
this.setLocation(100, 100); // Posicion desde la esquina superior izquierda del monitor
this.setSize(new Dimension(600, 350)); // Dimensiones
// Se inserta el botOn, se le pone color del fondo y color del frente (texto)
add(Boton); Boton.setBackground(Color.blue); Boton.setForeground(Color.yellow);
Boton.setBounds(10, 10, 60, 30); // Se posiciona
Boton.addActionListener(new Botonazo()); // Se captura el evento del ratOn sobre el botOn
// Se inserta el JLabel y se posiciona
add(Etiqueta); Etiqueta.setBounds(100, 100, 100, 30);
// Se inserta el JTextField y se posiciona
add(CAMPOTEXTO); CAMPOTEXTO.setBounds(100, 150, 100, 30);
setVisible(true); // 2.- Se muestra la ventana
}
public static void main(String R[]) { new Ventana(); }
// 3.- Captura del evento "cerrar ventana"
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); }
}
class Botonazo implements ActionListener
{
public void actionPerformed(ActionEvent EVENTO)
{
System.out.println(EVENTO.getActionCommand());
Etiqueta.setText("FIN");
}
}
}