Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- public class HelloWorld {
- public static void programStarter()
- {
- JFrame window = new JFrame("Aplicativo Willian");
- final JTextField txb = new JTextField("Digite seu texto aqui");
- JButton btn = new JButton("Continuar");
- MouseListener evento_txb = new MouseListener() {
- @Override
- public void mouseReleased(MouseEvent e) {
- }
- @Override
- public void mousePressed(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- if(txb.getText().isEmpty())
- {
- txb.setText("Digite seu texto aqui");
- }
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- if(txb.getText().contains("Digite seu texto aqui"))
- {
- txb.setText(null);
- }
- else if(!txb.getText().isEmpty())
- {
- txb.selectAll();
- }
- }
- };
- ActionListener evento_btn = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if(!txb.getText().isEmpty())
- {
- JOptionPane.showMessageDialog(new JFrame(), txb.getText().length());
- }
- else
- {
- JOptionPane.showMessageDialog(new JFrame(), "Digite algo no campo de texto!");
- }
- }
- };
- btn.addActionListener(evento_btn);
- txb.addMouseListener(evento_txb);
- //-------------------------------------------------
- window.add(txb,BorderLayout.CENTER);
- window.add(btn,BorderLayout.EAST);
- window.setBounds(1,1,300,80);
- window.setVisible(true);
- }
- public static void main(String[] args) {
- programStarter();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment