Skip to content

Commit

Permalink
Creación de la clase para la fase de despliegue
Browse files Browse the repository at this point in the history
  • Loading branch information
josruinav committed Jan 31, 2017
1 parent 417b1de commit b51f7ee
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/main/java/main/java/Despliegue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main.java;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class Despliegue extends JFrame implements ActionListener {

private JLabel texto; // etiqueta o texto no editable
private JTextField caja; // caja de texto, para insertar datos
private JButton boton; // boton con una determinada accion

public Despliegue() {
super(); // usamos el contructor de la clase padre JFrame
configurarVentana(); // configuramos la ventana
inicializarComponentes(); // inicializamos los atributos o componentes
}

private void configurarVentana() {
this.setTitle("Despliegue"); // colocamos titulo a la ventana
this.setSize(310, 210); // colocamos tamanio a la ventana (ancho, alto)
this.setLocationRelativeTo(null); // centramos la ventana en la pantalla
this.setLayout(null); // no usamos ningun layout, solo asi podremos dar posiciones a los componentes
this.setResizable(false); // hacemos que la ventana no sea redimiensionable
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // hacemos que cuando se cierre la ventana termina todo proceso
}

private void inicializarComponentes() {
// creamos los componentes
texto = new JLabel();
caja = new JTextField();
boton = new JButton();
// configuramos los componentes
texto.setText("Inserte Nombre"); // colocamos un texto a la etiqueta
texto.setBounds(50, 50, 100, 25); // colocamos posicion y tamanio al texto (x, y, ancho, alto)
caja.setBounds(150, 50, 100, 25); // colocamos posicion y tamanio a la caja (x, y, ancho, alto)
boton.setText("Mostrar Mensaje"); // colocamos un texto al boton
boton.setBounds(50, 100, 200, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
boton.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
// adicionamos los componentes a la ventana
this.add(texto);
this.add(caja);
this.add(boton);
}

@Override
public void actionPerformed(ActionEvent e) {
String nombre = caja.getText(); // obtenemos el contenido de la caja de texto
JOptionPane.showMessageDialog(this, "Hola " + nombre + "."); // mostramos un mensaje (frame, mensaje)
}

public static void main(String[] args) {
Despliegue V = new Despliegue(); // creamos una ventana
V.setVisible(true); // hacemos visible la ventana creada
}
}

0 comments on commit b51f7ee

Please sign in to comment.