-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathConsole.java
More file actions
66 lines (61 loc) · 2.01 KB
/
Copy pathConsole.java
File metadata and controls
66 lines (61 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package application;
import javafx.stage.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.effect.*;
import javafx.beans.value.*;
import javafx.scene.paint.*;
import javafx.scene.input.*;
import javafx.scene.text.*;
import javafx.geometry.*;
import javafx.event.*;
import java.util.*;
// This is just a few command tests
public class Console {
public static void runCommand(String input, String username, Label termArea) {
String command = new String();
String body = new String();
if(!input.contains(" ")){
command = input.trim();
body = "null";
}
else
{
command = input.split(" ", 2)[0];
body = input.split(" ", 2)[1];
if(body.trim().equals("")) {
body = "null";
}
}
if(termArea.getText().trim().equals("")) {
termArea.setText(" " + username + input);
}
else
{
termArea.setText(termArea.getText() + "\n " + username + input);
}
if(!Arrays.asList("echo", "clear", "help").contains(command)) {
termArea.setText(termArea.getText() + "\n \"" + command + "\" is not a valid command.\n");
}
else
{
if (command.trim().equals("help")) {
termArea.setText(termArea.getText() + "\n help - Shows a list of all commands"
+"\n echo - Prints text to console"
+"\n clear - Clears the console\n");
}
else if(command.trim().equals("echo")) {
if(!body.equals("null")) {
termArea.setText(termArea.getText() + "\n " + body + "\n");
}
else
{
termArea.setText(termArea.getText() + "\n");
}
}
else if (command.trim().equals("clear")) {
termArea.setText("");
}
}
}
}