Avevo una bella giornata:
codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Andrea
*/
public class InputParser extends JFrame {
private class myTextArea extends JTextArea implements KeyListener {
private String consoleInput;
public void keyReleased (KeyEvent ke) {
if (ke.getKeyCode() == ke.VK_ENTER) {
try {
String temp = this.getText(this.getLineStartOffset(this.getLineCount()-2),this.getLineEndOffset(this.getLineCount()-2));
System.out.println(temp);
}
catch (Exception e) {
e.printStackTrace();
}
this.append(consoleInput);
this.setCaretPosition(this.getText().length());
}
}
public void keyPressed(KeyEvent ke) {
}
public void keyTyped (KeyEvent ke) {
}
public myTextArea(String consoleInput) {
this.consoleInput = consoleInput;
this.setText(consoleInput);
this.setCaretPosition(this.getText().length());
this.addKeyListener(this);
}
}
/** Creates a new instance of InputParser */
public InputParser() {
super("test");
myTextArea mta = new myTextArea("C:\\>");
this.setSize(400,400);
this.getContentPane().add(new JScrollPane(mta));
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args) {
InputParser ip = new InputParser();
}
}