Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.8 kB
2
Indexable
Never
/**
 *
 *  @author Grzegorczyk Jakub S20813
 *
 */

package zad2;


import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.Border;
import javafx.scene.layout.GridPane;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javafx.geometry.Insets;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

import javax.swing.*;

public class Main {

  public static void main(String[] args) {
    Service s = new Service("Italy");
    String weatherJson = s.getWeather("Rome");
    Double rate1 = s.getRateFor("USD");
    Double rate2 = s.getNBPRate();

    System.out.println(weatherJson);
    System.out.println(rate1);
    System.out.println(rate2);
    // ...
    // część uruchamiająca GUI

    JFrame frame = new JFrame();
    JLabel weather = new JLabel("Weather: " + weatherJson);
    JLabel currRate = new JLabel("Rate: " + rate1);
    JLabel nbpRate = new JLabel("NBP rate: " + rate2);


    JButton button = new JButton("Provide New Data");
    button.setBounds(0,0,10,10);

    button.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        JPanel newInput = new JPanel();
        JTextField country = new JTextField(10);
        JTextField city = new JTextField(10);
        JTextField currencyCode = new JTextField(4);
        newInput.add(new JLabel("Country:"));
        newInput.add(country);
        newInput.add(Box.createHorizontalStrut(15));
        newInput.add(new JLabel("City:"));
        newInput.add(city);
        newInput.add(Box.createHorizontalStrut(15));
        newInput.add(new JLabel("Currency:"));
        newInput.add(currencyCode);

        int result = JOptionPane.showConfirmDialog(null, newInput,
                "Please enter new values", JOptionPane.OK_CANCEL_OPTION);
      }});

    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
    labelPanel.add(weather);
    labelPanel.add(currRate);
    labelPanel.add(nbpRate);

    frame.add(BorderLayout.NORTH, labelPanel);
    frame.add(BorderLayout.WEST, button);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);


  }

}

//    WebView browser = new WebView();
//    WebEngine webEngine = browser.getEngine();
//    String www  = "https://pl.wikipedia.org/wiki/Rome";
//    webEngine.load(www);

//    Scene scene = new Scene(browser);
//    JFXPanel jfxPanel = new JFXPanel();
//    jfxPanel.setScene(scene);
//    frame.add(BorderLayout.SOUTH, jfxPanel);