Skip to content
Open
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
12 changes: 12 additions & 0 deletions .idea/artifacts/AphorismsClient.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/artifacts/AphorismsServer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/artifacts/ControlerElectricClock.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/artifacts/ExchangeClient.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/artifacts/MessenferClient.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/artifacts/MessengerServer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/artifacts/ServerElectricClock.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions Java-lab-6.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resourses" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="commons-io:commons-io:2.6" level="project" />
<orderEntry type="library" name="org.codeartisans:org.json:20161124" level="project" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added out/artifacts/ExchangeClient/Java-lab-6.jar
Binary file not shown.
Binary file added out/artifacts/MessenferClient/MessenferClient.jar
Binary file not shown.
Binary file added out/artifacts/MessengerServer/MessengerServer.jar
Binary file not shown.
Binary file not shown.
Binary file added resourses/Balaton.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions resourses/Messeges.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"id": "111",
"time": "05:59",
"mes": "Natasha, do you sleep? It`s your cats!"
},
{
"id": "111",
"time": "06:00",
"mes": "Natasha, wake up! It`s 6 o`clock now!"
},
{
"id": "111",
"time": "06:01",
"mes": "Natasha, we have dropped everything!"
},
{
"id": "111",
"time": "06:02",
"mes": "Natasha, we really have dropped everything!",
"isLast": true
},
{
"id": "222",
"time": "12:24",
"mes": "Hey, stop watching cat video on youtube! Let`s do something useful!"
},
{
"id": "222",
"time": "12:25",
"mes": "So, do you start write your code?"
},
{
"id": "222",
"time": "12:26",
"mes": "Continue to work!"
},
{
"id": "222",
"time": "23:00",
"mes": "Not bad! It`s enough for today, you can go to bed!",
"isLast": true
},
{
"id": "333",
"time": "17:58",
"mes": "It`s time to check your mail!"
},
{
"id": "333",
"time": "18:05",
"mes": "It`s time to go home...",
"isLast": true
}
]
20 changes: 20 additions & 0 deletions resourses/Nietzsche.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"Если вы решили действовать — закройте двери для сомнений." Ф.Ницше
"Человек есть нечто, что до́лжно превзойти." Ф.Ницше
"Счастье человека зависит от его мыслей." Ф.Ницше
"Наш долг — это право, которое другие имеют на нас." Ф.Ницше
"Много говорить о себе – тоже способ себя скрывать." Ф.Ницше
"Если у человека есть зачем, он вынесет любое как." Ф.Ницше
"Не то, что ты обманул меня, а то, что я больше не могу верить тебе, потрясло меня." Ф.Ницше
"Чем больше человек молчит, тем больше он начинает говорить разумно." Ф.Ницше
"Без музыки жизнь была бы заблуждением." Ф.Ницше
"Я даю себя обманывать, чтобы не остерегаться обманщиков." Ф.Ницше
"Хороший брак покоится на таланте к дружбе." Ф.Ницше
"Невозможно быть свободным от того, от чего убегаешь." Ф.Ницше
"Я пришел помочь вам, а вы жалуетесь, что я не хочу плакать с вами." Ф.Ницше
"Где нельзя уже любить, там нужно — пройти мимо!" Ф.Ницше
"Красота — это обещание счастья." Ф.Ницше
"Иногда люди не хотят слышать правду, потому что они не хотят, чтобы их иллюзии были разрушены." Ф.Ницше
"Величайшие события — это не нашисамые шумные, а наши самые тихие часы." Ф.Ницше
"Кто не может повелевать себе, должен повиноваться." Ф.Ницше
"Даже у Бога есть свой ад — это любовь его к людям." Ф.Ницше
"Ни один победитель не верит в случайность." Ф.Ницше
Binary file added src/ExchangeClient/Balaton.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions src/ExchangeClient/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ExchangeClient;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;

import java.io.IOException;
import java.net.URL;
import java.util.*;

;

public class Controller implements Initializable {
ExchangeClient exchangeClient = new ExchangeClient();

@FXML
private Button show;
@FXML
private Button off;
@FXML
private Label display;
@FXML
private TextField field;
@FXML
private ImageView picture;

@Override
public void initialize(URL location, ResourceBundle resources) {
System.out.println("Controllers is initialiaezed!");
display.setWrapText(true);
}

@FXML
private void clickShow () throws IOException {
Timer t1 = new Timer();
t1.schedule(new ExchangeClientTimerTask() {
@Override
public void run() {
System.out.println("ExchangeClientTimerTask is started" + new Date());
try {
exchangeClient.contactToServer();
ArrayList<String> exchangeRates = exchangeClient.getExchangeRates();
for (int i = 0; i<exchangeRates.size(); i++) {
String toSet = exchangeRates.get(i);
Platform.runLater(()-> display.setText(toSet));
Thread.sleep(2500);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}, 0);

}

class ExchangeClientTimerTask extends TimerTask {
@Override
public void run() {
System.out.println("ExchangeClientTimerTask is started" + new Date());
completeTask();
System.out.println("ExchangeClientTimerTask is finished" + new Date());

}
private void completeTask() {
try {
Thread.sleep(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

@FXML
private void clickOff() throws IOException {
display.setText("I hope you like it! Bye!");
}
}
64 changes: 64 additions & 0 deletions src/ExchangeClient/ExchangeClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ExchangeClient;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.NoRouteToHostException;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

public class ExchangeClient {
private static String CURRENCY_INFO_URL = "https://cbr.ru/currency_base/daily/";
private ArrayList<String> currency = new ArrayList<>(
Arrays.asList(new String[]{"EUR", "CZK", "BYN", "USD", "GBP", "CHF", "TRY", "PLN"}));
private URL url;
private ArrayList<Element> exchangeRates = new ArrayList<>();

public void contactToServer () throws IOException {
try {
System.out.println("The client is started!");
url = new java.net.URL(CURRENCY_INFO_URL);
Document html = Jsoup.parse(url, 5000);
Elements rows = html.body().getElementsByTag("tr");
for (Element el : rows) {
if (currency.contains(el.child(1).text())) {
exchangeRates.add(el);
}
}
} catch (UnknownHostException e) {
System.out.println("The host isn`t found!");
} catch (NoRouteToHostException e) {
System.out.println("The server isn`t available!");
} catch (IOException e) {
System.out.println("The connection request is rejected!");
}
System.out.println("The client is disconnected!");
}

public ArrayList<String> getExchangeRates() {
ArrayList<String> exchRates = new ArrayList<>();
for (int i = 0; i<exchangeRates.size(); i++) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yy");
String actualTime = dateFormat.format(new Date());
String information = "For today " + actualTime + " 1 " + exchangeRates.get(i).child(1).text()
+ " (" + exchangeRates.get(i).child(3).text()+ ")" + " costs "
+ exchangeRates.get(i).child(4).text() + " russian rubles";
System.out.println(information);
exchRates.add(information);
}
return exchRates;
}

public static void main(String[] args) throws IOException {
ExchangeClient justClient = new ExchangeClient();
justClient.contactToServer();
justClient.getExchangeRates();
}
}
24 changes: 24 additions & 0 deletions src/ExchangeClient/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ExchangeClient;

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("sample4.fxml"));
primaryStage.setTitle("Exchange Client");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
primaryStage.show();
}


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