Reputation: 81
I've created a chat in java with a GUI and a textField to send Messages. I can also type for commands (like "§example") there.
But In the chat I want to create a "§kick [user]" command. How can I get the argument [user] in the
public void runCommand() {
if(textField.getText().equals("§kick")) {
appendTextMessages("kicked " + user);
textField.setText(null);
textField.requestFocus();
}
}
Hope you understand the question!
Thanks in advance
Upvotes: 1
Views: 71
Reputation: 32680
Well, typically I click a button to submit what I've typed into whatever text field to whatever website/web-app I'm submitting to... So, when I click that button, you check the contents of that text field to get what I've inputted and process it in essentially the same way you learned to do so with a Scanner
in introductory Java,
Upvotes: 1
Reputation: 53829
Try:
String text = textField.getText();
if(text.starstWith("§kick ")) {
String user = text.substring("§kick ".length());
// kick user
// ...
}
Upvotes: 0