Skip to content
Open

b35 #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added AphorismServer/AphorismServer.jar
Binary file not shown.
22 changes: 22 additions & 0 deletions AphorismServer/src/client/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package client;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Client extends Application {

@Override
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("client.fxml"));
stage.setTitle("Client");
stage.setScene(new Scene(root));
stage.show();
}

public static void main(String[] args) {
launch(args);
}
}
84 changes: 84 additions & 0 deletions AphorismServer/src/client/ClientController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package client;

import javafx.fxml.FXML;

import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;

public class ClientController {
@FXML
private Button btnConnect;
@FXML
private Button btnExit;
@FXML
private Button btnNew;
@FXML
private TextArea taDisplay;
@FXML
private TextField tfServerIP;
@FXML
private TextField tfState;

Socket clientSocket = null;

private void getAphorism(){
ClientProcess process = new ClientProcess(this.clientSocket);
Thread thread = new Thread(process);
thread.setDaemon(true);
thread.start();
taDisplay.textProperty().bind(process.messageProperty());
}

public void setBtnExit(){
try {
PrintWriter pwOut = new PrintWriter(this.clientSocket.getOutputStream(), true);
pwOut.println("exit");
System.exit(0);
}
catch (NullPointerException e){
tfState.setText("Nothing for disconnect");
}
catch (IOException e){
tfState.setText("Disconnection error");
}
}

public void getConnect() throws IOException {
String sServerIP = tfServerIP.getText();
tfState.setText("Connecting with "+sServerIP+"...");
try{
this.clientSocket = new Socket(sServerIP,2020);
tfState.setText("Connection with "+sServerIP+" success");
}
catch (UnknownHostException e){
tfState.setText("Connection failed: Unknown host");
}
catch (NoRouteToHostException e){
tfState.setText("Connection failed: No connection");
}
catch (ConnectException e){
tfState.setText("Connection failed: Connection error");
}
catch (IOException e){
tfState.setText("Connection failed: Input/output error");
}

getAphorism();
}

public void setBtnNew(){
if (clientSocket == null){
tfState.setText("No connection");
}
else {
getAphorism();
}
}
}
42 changes: 42 additions & 0 deletions AphorismServer/src/client/ClientProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package client;

import javafx.concurrent.Task;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class ClientProcess extends Task<Void>{

private Socket clientSocket;

public ClientProcess(Socket clientSocket) {
this.clientSocket = clientSocket;
}

@Override
public Void call() {
getTime();
return null;
}

public void getTime(){
BufferedReader brIn = null;
PrintWriter pwOut = null;
String sInput=null;
try{
brIn = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
pwOut = new PrintWriter(this.clientSocket.getOutputStream(),true);
}
catch (IOException e) {}

pwOut.println("aphorism");
try {
sInput = brIn.readLine();
updateMessage(sInput);
}
catch (IOException e){}
}
}
106 changes: 106 additions & 0 deletions AphorismServer/src/client/client.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.ClientController">
<children>
<VBox alignment="CENTER" prefHeight="400.0" prefWidth="600.0">
<children>
<VBox prefHeight="100.0" prefWidth="600.0">
<children>
<HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="Input server IP">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<TextField fx:id="tfServerIP">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</TextField>
</children>
</HBox>
<HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="State">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Label>
<TextField fx:id="tfState" editable="false" minWidth="250.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</TextField>
</children>
</HBox>
</children>
</VBox>
<TextArea fx:id="taDisplay" editable="false" prefHeight="200.0" prefWidth="200.0" wrapText="true">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<font>
<Font size="17.0" />
</font>
</TextArea>
<HBox alignment="CENTER" prefHeight="200.0" prefWidth="600.0">
<children>
<Button fx:id="btnConnect" mnemonicParsing="false" onAction="#getConnect" prefHeight="50.0" prefWidth="150.0" text="CONNECT">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<font>
<Font size="15.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#setBtnNew" prefHeight="50.0" prefWidth="150.0" text="NEW APHORISM">
<font>
<Font size="15.0" />
</font>
</Button>
<Button fx:id="btnExit" mnemonicParsing="false" onAction="#setBtnExit" prefHeight="50.0" prefWidth="150.0" text="DISCONNECT">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<font>
<Font size="15.0" />
</font>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
</Pane>
23 changes: 23 additions & 0 deletions AphorismServer/src/main/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
primaryStage.setTitle("Server Clock");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}
32 changes: 32 additions & 0 deletions AphorismServer/src/main/MainController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main;

import client.Client;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import server.Server;

public class MainController {
@FXML
private Button btnServer;
@FXML
private Button btnClient;

public void setBtnServer(){
Server server = new Server();
Stage stage = new Stage();
try {
server.start(stage);
}
catch (Exception e){}
}

public void setBtnClient(){
Client client = new Client();
Stage stage = new Stage();
try {
client.start(stage);
}
catch (Exception e){}
}
}
31 changes: 31 additions & 0 deletions AphorismServer/src/main/main.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.MainController">
<children>
<HBox alignment="CENTER" prefHeight="200.0" prefWidth="300.0">
<children>
<Button fx:id="btnServer" mnemonicParsing="false" onAction="#setBtnServer" prefHeight="30.0" prefWidth="100.0" text="SERVER">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</Button>
<Button fx:id="btnClient" mnemonicParsing="false" onAction="#setBtnClient" prefHeight="30.0" prefWidth="100.0" text="CLIENT">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</Button>
</children>
</HBox>
</children>
</Pane>
19 changes: 19 additions & 0 deletions AphorismServer/src/server/Aphorism.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package server;

public class Aphorism {
private String aphorism;
private String author;

public Aphorism(String aphorism, String author) {
this.aphorism = aphorism;
this.author = author;
}

public String getAphorism() {
return aphorism;
}

public String getAuthor() {
return author;
}
}
22 changes: 22 additions & 0 deletions AphorismServer/src/server/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package server;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Server extends Application {

@Override
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("server.fxml"));
stage.setTitle("Server");
stage.setScene(new Scene(root));
stage.show();
}

public static void main(String[] args) {
launch(args);
}
}
Loading