SHARE
TWEET

Exercicio 1 feito

Alfoli Feb 26th, 2020 (edited) 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.BorderLayout;
  2. import java.awt.GridLayout;
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.HashSet;
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import javax.swing.JButton;
  10. import javax.swing.JPanel;
  11. import javax.swing.JTextField;
  12. import javax.swing.SwingConstants;
  13.  
  14. public class Conversor extends JFrame implements ActionListener{
  15.     JTextField texto;
  16.     JButton btnTamanho, btnMaius, btnMinus, btnLimpar;
  17.     JLabel txtEntrada, txtTamanho, txtIam;
  18.     JTextField txtCont1, txtCont2, txtCont3;
  19.    
  20.     public void actionPerformed (ActionEvent e) {
  21.         if (e.getSource() == btnLimpar) {
  22.             texto.setText("");
  23.         }
  24.         if (e.getSource() == btnTamanho) {
  25.             int tam = texto.getText().length();
  26.             txtIam.setText(String.format("%d", tam));
  27.         }
  28.         if (e.getSource() == btnMaius) {
  29.             texto.setText(String.format("%s", texto.getText().toUpperCase()));
  30.         }
  31.         if (e.getSource() == btnMinus) {
  32.             texto.setText(String.format("%s", texto.getText().toLowerCase()));
  33.         }
  34.     }
  35.     public Conversor() {
  36.         setLayout(new BorderLayout());
  37.         btnTamanho = new JButton ("Tamanho");
  38.         btnMaius = new JButton ("Maiusculo");
  39.         btnMinus = new JButton ("Minusculo");
  40.         btnLimpar = new JButton ("Limpar");
  41.         JPanel sul = new JPanel (new GridLayout(5,1));
  42.         sul.add(btnTamanho);
  43.         sul.add(btnMaius);
  44.         sul.add(btnMinus);
  45.         sul.add(btnLimpar);
  46.         add (sul, BorderLayout.SOUTH);
  47.        
  48.         JPanel centro = new JPanel (new GridLayout (5,1));
  49.         txtEntrada = new JLabel ("Digite um texto:   ", SwingConstants.RIGHT); //try left
  50.         txtTamanho = new JLabel ("Tamanho:    ", SwingConstants.RIGHT);
  51.         txtIam = new JLabel ("", SwingConstants.RIGHT);
  52.         texto = new JTextField (5);
  53.         centro.add(txtEntrada);
  54.         centro.add(texto);
  55.         centro.add(txtTamanho);
  56.         centro.add(txtIam);
  57.         add(centro, BorderLayout.CENTER);
  58.         btnTamanho.addActionListener(this);
  59.         btnMaius.addActionListener(this);
  60.         btnMinus.addActionListener(this);
  61.         btnLimpar.addActionListener(this);
  62.     }
  63.     public static void main(String[] args) {
  64.         Conversor tela = new Conversor();
  65.         tela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  66.         tela.setSize(350, 250);
  67.         tela.setLocation(500,500);
  68.         tela.setVisible(true);
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top