joeykiske
30-04-2010, 02:31
Salve!
sto provando a conoscere quanti caratteri sono stati scritti nella JTA comunicandoli direttamente su di una label.........
posto il codice del programma di prova..
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
public class Prova04
{
static int numlabel;
public static void main(String[] args)
{
JFrame w = new JFrame("Prova TXA");
final JTextArea t = new JTextArea(3,4);
w.setLayout(new BorderLayout());
w.add(t,BorderLayout.NORTH);
//DOCUMENTO PER PRELEVARE LA JTEXTAREA
Document prova = t.getDocument();
//LISTENER
prova.addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent e)
{ a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
public void insertUpdate(DocumentEvent e)
{a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
public void removeUpdate(DocumentEvent e)
{a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
});
//TRASFORMARE NUMERO IN STRINGA POI IN LABEL
String numero = Integer.toString(numlabel);
JLabel asd = new JLabel(numero);
w.add(asd,BorderLayout.SOUTH);
w.pack();
w.setVisible(true);
}
}
.....Voi come avreste implementato il codice?!?!
è una mia curiosità,nulla di più :p :p
grazie anticipatamente!!
sto provando a conoscere quanti caratteri sono stati scritti nella JTA comunicandoli direttamente su di una label.........
posto il codice del programma di prova..
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
public class Prova04
{
static int numlabel;
public static void main(String[] args)
{
JFrame w = new JFrame("Prova TXA");
final JTextArea t = new JTextArea(3,4);
w.setLayout(new BorderLayout());
w.add(t,BorderLayout.NORTH);
//DOCUMENTO PER PRELEVARE LA JTEXTAREA
Document prova = t.getDocument();
//LISTENER
prova.addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent e)
{ a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
public void insertUpdate(DocumentEvent e)
{a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
public void removeUpdate(DocumentEvent e)
{a = e.getDocument().getLength());
System.out.print(e.getDocument().getLength();
}
});
//TRASFORMARE NUMERO IN STRINGA POI IN LABEL
String numero = Integer.toString(numlabel);
JLabel asd = new JLabel(numero);
w.add(asd,BorderLayout.SOUTH);
w.pack();
w.setVisible(true);
}
}
.....Voi come avreste implementato il codice?!?!
è una mia curiosità,nulla di più :p :p
grazie anticipatamente!!