Java : Crear un formulario que Guarde el mensaje al introducir el texto en la caja
Clase 1/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejformulario;
/**
*
* @author Clases
*/
public class Ejformulario {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Clase 2
package ejformulario;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
public class PruebaFormulario {
public static void main(String[] args) {
Marco mimarco=new Marco();
mimarco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mimarco.setVisible(true);
}
}
class Marco extends JFrame{
Marco(){
setTitle("Formulario My Little Pony");
setSize(400,400);
Panel lamina=new Panel();
add(lamina);
}
}
class Panel extends JPanel {
JTextField caja1;
JButton boton1;
JLabel etiqueta1;
Panel() {
boton1=new JButton("");
boton1.setText("Aceptar");
boton1.setSize(20,20);
caja1=new JTextField();
caja1.setColumns(10);
caja1.setSize(20, 10);
add(caja1);
add(boton1);
Accion accionboton=new Accion();
boton1.addActionListener(accionboton);
}
private class Accion implements ActionListener{
public void actionPerformed(ActionEvent e)
{
etiqueta1=new JLabel();
add(etiqueta1);
etiqueta1.setText(caja1.getText());
}
}
Copyright : Inacap