private JLabel commandLabel;
- private JTextField command;
+ private JTextField commandField;
private JLabel answersLabel;
- private JTextArea answers;
+ private JTextArea answersArea;
public CommandPanel(Netzdose netzdose) {
this.netzdose = netzdose;
top.setLayout(new BorderLayout());
commandLabel = new JLabel("Command:");
top.add(commandLabel, BorderLayout.WEST);
- command = new JTextField();
- command.addActionListener(new ActionListener() {
+ commandField = new JTextField();
+ commandField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply();
}
});
- top.add(command, BorderLayout.CENTER);
+ top.add(commandField, BorderLayout.CENTER);
add(top, BorderLayout.NORTH);
JPanel middle = new JPanel();
commandCounter = 0;
answersLabel = new JLabel("Answers:");
middle.add(answersLabel, BorderLayout.WEST);
- answers = new JTextArea();
- answers.setEditable(false);
- middle.add(new JScrollPane(answers,
+ answersArea = new JTextArea();
+ answersArea.setEditable(false);
+ middle.add(new JScrollPane(answersArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
BorderLayout.CENTER);
}
protected void reset() {
- command.setText("");
+ commandField.setText("");
}
protected void apply() {
- Command cmd;
- String commandText = command.getText();
+ Command command;
+ String commandText = commandField.getText();
try {
- cmd = new Command(commandText);
+ command = new Command(commandText);
} catch (RuntimeException e) {
LogMediator.getInstance(this.getClass()).log(
"Kann \"" + commandText + "\" nicht in Command wandeln.");
return;
}
- LogMediator.getInstance(this.getClass()).log("Sende " + cmd);
- byte[] answerBytes = netzdose.sendCommand(cmd);
- answers.append(++commandCounter + ": "
+ LogMediator.getInstance(this.getClass()).log("Sende " + command);
+ byte[] answerBytes = netzdose.sendCommand(command);
+ answersArea.append(++commandCounter + ": "
+ new Command(answerBytes).toString() + "\n");
- command.setText("");
+ commandField.setText("");
}
}