How to combine characters
- From: Chris <chrisliapis@xxxxxxxxx>
- Date: Sun, 22 Jun 2008 15:26:38 -0700 (PDT)
All,
Someone helped me with this code a few weeks ago, and it works
great! However I wanted to know if I could alter it. That is, the
output variable is a char. I am trying to see if I can combine the
chars being typed in until a spacebar is typed. This way instead of
outputting a char, the chars will combine into a String (hence a word)
whereby the spacebar delineates a new word being typed in....
So if I type "test" in the textfield, it wont output each char
seperately, but it will output the full word "test".
Does anyone know how to combine chars to make a word?
Thank you so much for your help...
import java.awt.*;
import java.awt.event.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;
import java.util.*;
public class InputObject {
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField tf = new JTextField(30);
tf.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke)
{
String s = "" + ke.getKeyChar();
System.out.println(s);
//Here lookiing to combine chars to a string
ke.consume();
}
});
f.add(tf,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
});
}
}
.
- Follow-Ups:
- Re: How to combine characters
- From: Daniele Futtorovic
- Re: How to combine characters
- Prev by Date: Re: equally sizing text areas inside of a JTabbedPane
- Next by Date: Re: How to combine characters
- Previous by thread: character issues in read-only JTextArea
- Next by thread: Re: How to combine characters
- Index(es):
Relevant Pages
|