Android Open Source - MobileDev_beginner Text Field Test






From Project

Back to project page MobileDev_beginner.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project MobileDev_beginner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * @(#)TextFieldTest.java//from w w w.  j  a  v a2  s.  co m
 *
 *
 * @author
 * @version 1.00 2014/7/14
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TextFieldTest extends JFrame {
  private JTextField tField1, tField2, tField3;
  private JPasswordField pField;

  //GUI section
    public TextFieldTest() {
      super ("Test out JTextField and JPasswordField");

      Container container = getContentPane();
      container.setLayout( new FlowLayout());

      //tField with default size
      tField1 = new JTextField(10);
      container.add(tField1);

      //tField with default text
      tField2 = new JTextField("Enter something here");
      container.add(tField2);

      //20 visible element - no event handler
      tField3 = new JTextField("Uneditable text field", 20);
      tField3.setEditable(false);
      container.add(tField3);

      //pField with default text
      pField = new JPasswordField("Hidden text");
      container.add(pField);

      //register event handlers
      TextFieldHandler handler = new TextFieldHandler();
      tField1.addActionListener(handler);
      tField2.addActionListener(handler);
      tField3.addActionListener(handler);
      pField.addActionListener(handler);

      setSize( 350, 125);
      setVisible(true);
    }

    public static void main (String[] args) {
      TextFieldTest app = new TextFieldTest();
      app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    //private inner class for event handling
    private class TextFieldHandler implements ActionListener {

      //process textfield events
      public void actionPerformed(ActionEvent event) {

        String string = "";

        //user pressed enter in tField1
        if (event.getSource() == tField1)
          string = "tField1: " + event.getActionCommand();

        //user pressed enter in tField2
        else if (event.getSource() == tField2)
          string = "tField2: " + event.getActionCommand();

        //user pressed enter in tField3
        else if (event.getSource() == tField3)
          string = "tField3: " + event.getActionCommand();

        //user pressed enter in tField1
        else if (event.getSource() == pField) {

          string = "pField: " + new String(pField.getPassword() );
        }

        JOptionPane.showMessageDialog( null, string);
      }
    }

}




Java Source Code List

.CheckBoxTest.java
.Demo.java
.ListTest.java
.OurServlet.java
.TextFieldTest.java
com.corruptor.smssender.smsMenu.java
com.example.login.insidemenu.java
com.example.login.loginact.java
org.corruptor.Booking.java
org.corruptor.Car.java
org.corruptor.Customer.java
org.corruptor.Login.java
org.corruptor.Menu.java
org.corruptor.MyConnection.java
org.corruptor.MyMain.java
org.corruptor.MyScanner.java
org.corruptor.Reports.java