-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creación de la clase para la fase de despliegue
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |