hi i have this simple code that reads a line from console, now i want to read this line from a textarea just like console ( by pressing enter the line should be read ) what should i do ?
private DataInputStream co = null;
private DataOutputStream streamOut = null;
public void run()
{ while (thread != null)
{ try
{
streamOut.writeUTF(co.readLine());
streamOut.flush();
}
catch(IOException ioe)
{ System.out.println("Sending error: " + ioe.getMessage());
stop();
}
}
}
Attach KeyListener to your textarea, wait until enter will be pressed then get textarea’s text, split it by line breaks and get last line.
Or, you can make your KeyListener append each key pressed into StringBuilder and reset builder every time user press enter.