whiplk

[Executável] - Contador de caracteres(Java Version)

Sep 6th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.JTextField;
  11.  
  12. public class HelloWorld {
  13.  
  14.     public static void programStarter()
  15.     {
  16.         JFrame window = new JFrame("Aplicativo Willian");
  17.         final JTextField txb = new JTextField("Digite seu texto aqui");
  18.         JButton btn = new JButton("Continuar");
  19.        
  20.         MouseListener evento_txb = new MouseListener() {
  21.            
  22.             @Override
  23.             public void mouseReleased(MouseEvent e) {              
  24.             }
  25.            
  26.             @Override
  27.             public void mousePressed(MouseEvent e) {
  28.             }
  29.            
  30.             @Override
  31.             public void mouseExited(MouseEvent e) {
  32.                 if(txb.getText().isEmpty())
  33.                 {
  34.                     txb.setText("Digite seu texto aqui");
  35.                 }
  36.             }
  37.            
  38.             @Override
  39.             public void mouseEntered(MouseEvent e) {               
  40.             }
  41.            
  42.             @Override
  43.             public void mouseClicked(MouseEvent e) {
  44.                 if(txb.getText().contains("Digite seu texto aqui"))
  45.                 {
  46.                     txb.setText(null);
  47.                 }
  48.                 else if(!txb.getText().isEmpty())
  49.                 {
  50.                     txb.selectAll();
  51.                 }
  52.             }
  53.         };
  54.         ActionListener evento_btn = new ActionListener() {
  55.            
  56.             @Override
  57.             public void actionPerformed(ActionEvent e) {
  58.                 if(!txb.getText().isEmpty())
  59.                 {
  60.                     JOptionPane.showMessageDialog(new JFrame(), txb.getText().length());
  61.                 }
  62.                 else
  63.                 {
  64.                     JOptionPane.showMessageDialog(new JFrame(), "Digite algo no campo de texto!");
  65.                 }
  66.                
  67.             }
  68.         };
  69.        
  70.         btn.addActionListener(evento_btn);
  71.         txb.addMouseListener(evento_txb);
  72.        
  73.         //-------------------------------------------------
  74.        
  75.         window.add(txb,BorderLayout.CENTER);
  76.         window.add(btn,BorderLayout.EAST);
  77.         window.setBounds(1,1,300,80);
  78.         window.setVisible(true);
  79.     }
  80.     public static void main(String[] args) {
  81.         programStarter();
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment