Advertisement
gwserver

Janela com botão e tratamento de evento

May 10th, 2021
1,460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3.  
  4. public class ClassDesign {
  5.     public static void main(String[] args) {
  6.         JFrame janela = new JFrame("Exemplo de botão");
  7.         final JTextField campo = new JTextField();
  8.         campo.setBounds(50, 50, 150, 20);
  9.        
  10.         JButton botao = new JButton("Clique Aqui");
  11.         botao.addActionListener(
  12.                 new
  13.                 ActionListener() {
  14.                     public void actionPerformed(ActionEvent e) {
  15.                         campo.setText("Alô");
  16.                     }
  17.                 }
  18.         );
  19.         botao.setBounds(50, 100, 135, 30);
  20.  
  21.         janela.getContentPane().add(botao);
  22.         janela.getContentPane().add(campo);
  23.         janela.setSize(400, 400);
  24.         janela.getContentPane().setLayout(null);
  25.         janela.setVisible(true);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement