Como hacer que al apretar un botón aparezca un mensaje en JTextField

Iniciado por Shannon, 27 Marzo 2019, 06:40 AM

0 Miembros y 1 Visitante están viendo este tema.

Shannon

import javax.swing.*;
public class Practica1 extends JFrame{
   private JTextField eco;

   public Practica1(){
      setTitle("loro");
      JComponent botonera=creaBotonera();
      JComponent eco= creaEco();

      //crear panel con botonera y eco
      JSplitPane PanelPrincipal=
      new JSplitPane (JSplitPane.VERTICAL_SPLIT,botonera,eco);

      //añade el panel de la ventana principal
      getContentPane().add(PanelPrincipal);

      //se 'redimenciona' toda la interfaz grafica en la ventana
      pack();

      // y se hace visible la ventana, con sus componentes
      setVisible(true);
   }
   private JComponent creaBotonera(){
      JPanel botonera=new JPanel();

      // se crean los botones...
      JButton hola= new JButton("Di Hola");
      JButton adios = new JButton("Di Adios");

      // y se añade el panel
      botonera.add(hola);
      botonera.add(adios);
      return botonera;

   }
   private JComponent creaEco(){
      //se crea el mensaje
      eco=new JTextField("Pulsa un botón");

      return eco;
   }
   public static void main(String[] args){
      Practica1 loro=new Practica1();
   }

}
Código (java) [Seleccionar]
[color=green][/color]
His name will live, brother
No, I got-, I feel hella shitty because it's like, I '
Like, if I would have known it was so cool
And it's like, I ', if I would have watched interviews sooner, bro', we were so alike
It's unfortunate because it's like, me, when people die, that's when you're there, you know?
'Cause your remorse kinda makes you check' em out