Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: JTextfield
|
Posted: Apr 18, 2002 4:01 PM
|
|
Chris, I believe this helps ? Beware that you need to slightly resize the window to see its content... I still dunno why ...
package test.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldLength
{
public JFrame jf = new JFrame("JFrame");
public Frame f = new Frame ("Frame");
public TextField tf;
public JTextField jtf;
public JButton jb = new JButton("Validate");
TextFieldLength ()
{
jf.setVisible (true);
jf.setSize (500, 200);
jf.setLocation ( 0, 0);
jtf = new JTextField (10);
jf.getContentPane ().add (jtf, BorderLayout.CENTER);
jb.addActionListener (new CustomActionListener ());
jf.getContentPane ().add (jb, BorderLayout.EAST);
jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
f.setVisible (true);
f.setSize (300, 300);
f.setLocation (500, 200);
tf = new TextField (10);
f.add (tf, BorderLayout.CENTER);
}
/**
*
*/
public static void main (String[] args)
{
new TextFieldLength();
}
class CustomActionListener
implements ActionListener
{
public void actionPerformed (ActionEvent anActionEvent)
{
System.out.println ("Button pushed");
System.out.println ("There is " + jtf.getDocument ().getLength () + " character");
}
}
}
I can only enough advise you to use inner class they are really smthg beautyfull to handle events
Thomas SMETS SCJP, Brussels
|
|