hi,
im new to java , and im trying to get this to work , this is my code :
Java Code:
public class TextDemo extends JPanel implements ActionListener {
protected static JTextField commandField;
protected static JTextArea consoleArea;
protected static JTextArea outputArea;
private final static String newline = "\n";
public void actionPerformed(ActionEvent evt) {
String text = commandField.getText();
consoleArea.append(text + newline);
commandField.selectAll();
// Make sure the new text is visible, even if there
// was a selection in the text area.
consoleArea.setCaretPosition(consoleArea.getDocument().getLength());
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Client");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
JPanel left = new JPanel();
left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
consoleArea = new JTextArea(19,20);
JScrollPane scrollPaneConsole = new JScrollPane(consoleArea);
left.add(scrollPaneConsole);
commandField = new JTextField();
left.add(commandField);
left.setBorder(BorderFactory.createTitledBorder("Console"));
JPanel right = new JPanel();
right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
outputArea = new JTextArea(20,20);
JScrollPane scrollPaneOutput = new JScrollPane(outputArea);
right.add(scrollPaneOutput);
right.setBorder(BorderFactory.createTitledBorder("Output"));
contentPane.add(left);
contentPane.add(right);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[]) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
i want to be able to enter a text in the commandField and when pressing enter the text to be shown in the console area ,
why isnt my actionPerformed never gets called ??
No comments:
Post a Comment