|
|
@ -1,9 +1,14 @@ |
|
|
|
package window; |
|
|
|
|
|
|
|
import javafx.application.Application; |
|
|
|
import javafx.event.EventHandler; |
|
|
|
import javafx.geometry.Insets; |
|
|
|
import javafx.scene.Scene; |
|
|
|
import javafx.scene.control.*; |
|
|
|
import javafx.scene.input.InputMethodEvent; |
|
|
|
import javafx.scene.input.KeyCode; |
|
|
|
import javafx.scene.input.KeyEvent; |
|
|
|
import javafx.scene.input.MouseEvent; |
|
|
|
import javafx.scene.layout.*; |
|
|
|
import javafx.scene.paint.Color; |
|
|
|
import javafx.stage.Stage; |
|
|
@ -12,10 +17,12 @@ public class ChatWindow extends Application { |
|
|
|
|
|
|
|
public ChatWindow() { |
|
|
|
this.servername = "Serverless Chat Window"; |
|
|
|
this.username = "Localhost"; |
|
|
|
} |
|
|
|
|
|
|
|
public ChatWindow(String servername) { |
|
|
|
public ChatWindow(String servername, String username) { |
|
|
|
this.servername = servername; |
|
|
|
this.username = username; |
|
|
|
} |
|
|
|
|
|
|
|
public void addMessage(String user, String message) { |
|
|
@ -42,16 +49,29 @@ public class ChatWindow extends Application { |
|
|
|
AnchorPane.setRightAnchor(inputPane, 0.0); |
|
|
|
inputPane.prefHeightProperty().setValue(40); |
|
|
|
|
|
|
|
TextField inputBox = new TextField(); |
|
|
|
AnchorPane.setLeftAnchor(inputBox, 6.0); |
|
|
|
AnchorPane.setBottomAnchor(inputBox, 6.0); |
|
|
|
|
|
|
|
inputBox.setOnKeyReleased(keyEvent -> { |
|
|
|
if (keyEvent.getCode().equals(KeyCode.ENTER) && !inputBox.getText().equals("")) { |
|
|
|
addMessage(username, inputBox.getText()); // Change to sending this to the server when we have the server set up. |
|
|
|
inputBox.clear(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
Button inputButton = new Button("Send"); |
|
|
|
AnchorPane.setRightAnchor(inputButton, 6.0); |
|
|
|
AnchorPane.setBottomAnchor(inputButton, 6.0); |
|
|
|
inputButton.prefWidthProperty().setValue(80); |
|
|
|
inputButton.setOnMouseClicked(mouseEvent -> { |
|
|
|
if (!inputBox.getText().equals("")) { |
|
|
|
addMessage(username, inputBox.getText()); // Change to sending this to the server when we have the server set up. |
|
|
|
inputBox.clear(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
TextField inputBox = new TextField(); |
|
|
|
AnchorPane.setLeftAnchor(inputBox, 6.0); |
|
|
|
AnchorPane.setBottomAnchor(inputBox, 6.0); |
|
|
|
inputBox.prefWidthProperty().bind(inputPane.widthProperty().subtract(inputButton.prefWidthProperty()).subtract(18.0)); |
|
|
|
|
|
|
|
inputPane.getChildren().addAll(inputBox, inputButton); |
|
|
|
|
|
|
|
FlowPane usersPane = new FlowPane(); |
|
|
@ -75,14 +95,11 @@ public class ChatWindow extends Application { |
|
|
|
|
|
|
|
root.getChildren().addAll(statusBar, inputPane, usersPane, messagePane); |
|
|
|
primaryStage.show(); |
|
|
|
|
|
|
|
for (int i = 0; i < 400; i++) { |
|
|
|
addMessage("Anon", ""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) {launch(args);} |
|
|
|
|
|
|
|
private String servername; |
|
|
|
private Label messageLabel; |
|
|
|
private String username; |
|
|
|
private Label messageLabel; |
|
|
|
} |