Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Miciałkiewicz Mateusz S17331
- *
- */
- package zad1;
- import org.json.JSONObject;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Tab;
- import javafx.scene.control.TabPane;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TabPane.TabClosingPolicy;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.web.WebEngine;
- import javafx.scene.web.WebView;
- import javafx.stage.Stage;
- public class Main extends Application {
- private TextArea tekstArea;
- private Button weath, walu, waluNBP, wikiped;
- private WebView wwwView;
- private WebEngine wwwEngin;
- private Scene scen;
- private TabPane tabPane;
- private Tab tabli1, tabli2;
- private BorderPane bPMain, bPBttm, bPWeb;
- private HBox hebox;
- private static Service s;
- private static String weatherJson;
- private static Double rate1;
- private static Double rate2;
- private static String wikiAdr;
- private void preSgui(Stage primaryStage) {
- //Gui
- tabPane = new TabPane();
- tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
- tabli1 = new Tab("Opis");
- tabli2 = new Tab("Wikipedia");
- tabPane.getTabs().addAll(tabli1, tabli2);
- bPMain = new BorderPane();
- bPMain.setPadding(new Insets(18, 18, 18, 18));
- tekstArea = new TextArea();
- bPMain.setCenter(tekstArea);
- bPBttm = new BorderPane();
- bPBttm.setPadding(new Insets(12, 0, 0, 0));
- hebox = new HBox(16);
- weath = new Button("Pogoda");
- walu = new Button("waluty");
- waluNBP = new Button("NBP");
- wikiped = new Button("Załaduj wikipedia");
- hebox.getChildren().add(weath);
- hebox.getChildren().add(walu);
- hebox.getChildren().add(waluNBP);
- hebox.getChildren().add(wikiped);
- walu.setOnAction((event) -> {
- if (rate1 != null)
- showInfo("" + rate1);
- });
- weath.setOnAction((event) -> {
- if (weatherJson != null)
- showInfo(formatWeth(weatherJson));
- });
- wikiped.setOnAction((event) -> {
- if (wikiAdr != null)
- wwwEngin.load(wikiAdr);
- });
- waluNBP.setOnAction((event) -> {
- if (rate2 != null)
- showInfo("" + rate2);
- });
- bPBttm.setRight(hebox);
- bPMain.setBottom(bPBttm);
- tabli1.setContent(bPMain);
- bPWeb = new BorderPane();
- wwwView = new WebView();
- wwwEngin = wwwView.getEngine();
- bPWeb.setCenter(wwwView);
- tabli2.setContent(bPWeb);
- scen = new Scene(tabPane, 800, 600);
- }
- public void start(Stage primaryStage) {
- preSgui(primaryStage);
- primaryStage.setTitle("Info City");
- primaryStage.setScene(scen);
- primaryStage.show();
- }
- //dane do podmiany
- public static void main(String[] args) {
- s = new Service("Spain");
- weatherJson = s.getWeather("Madrid");
- rate1 = s.getRateFor("USD");
- rate2 = s.getNBPRate();
- wikiAdr = s.getWikiDescr("Madrid");
- launch(args);
- }
- public String formatWeth(String strin) {
- String formatStr = "";
- try {
- //wypisanie
- JSONObject jsonObj = new JSONObject(strin);
- if (!jsonObj.isNull("main")) {
- formatStr += "Temperatura aktualna: " + jsonObj.getJSONObject("main").get("temp") + "\n";
- formatStr += "Temperatura minimalna: " + jsonObj.getJSONObject("main").get("temp_min") + "\n";
- formatStr += "Temperatura max: " + jsonObj.getJSONObject("main").get("temp_max") + "\n";
- formatStr += "Wilgotnosc: " + jsonObj.getJSONObject("main").get("humidity") + "\n";
- formatStr += "Cisnienie: " + jsonObj.getJSONObject("main").get("pressure");
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- return formatStr;
- }
- public void showInfo(String rap) {
- tekstArea.clear();
- tekstArea.appendText(rap);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement