Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FXML
- Button bt1;
- @FXML
- Button bt2;
- public void bt1_click(ActionEvent actionEvent) throws Exception {
- PostLP.login = "логин1";
- PostLP.password = "пароль1";
- Application ap = new Boiler_control();
- ap.start(new Stage());
- }
- public void bt2_click(ActionEvent actionEvent) throws Exception {
- PostLP.login = "логин2";
- PostLP.password = "пароль2";
- Application ap = new Boiler_control();
- ap.start(new Stage());
- }
- package boilercontrolpanel;
- import javafx.application.Application;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.concurrent.Worker.State;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.ProgressBar;
- import javafx.scene.web.WebEngine;
- import javafx.scene.web.WebView;
- import javafx.stage.Stage;
- public class Boiler_control extends Application {
- public enum Status {
- login_request,
- control_request,
- }
- Status status = Status.login_request;
- String setLogin = "document.getElementsByName('username')[0].value='" + PostLP.login + "';";
- String setPassword = "document.getElementsByName('password')[0].value='" + PostLP.password + "';";
- String btnLogin = "document.getElementById('btnLogin').click();";
- @Override
- public void start(Stage primaryStage) throws Exception{
- Parent root = FXMLLoader.load(getClass().getResource("boiler_control.fxml"));
- WebView webView = (WebView) root.lookup("#web_view");
- webView.setVisible(true);
- WebEngine webEngine = webView.getEngine();
- webEngine
- webEngine.load("https://сайт");
- Label label = (Label) root.lookup("#label");
- ProgressBar progressBar = (ProgressBar) root.lookup("#prbar");
- progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty());
- webEngine.getLoadWorker().stateProperty().addListener(
- new ChangeListener<State>() {
- @Override
- public void changed(ObservableValue ov, State oldState, State newState) {
- if (newState == State.SUCCEEDED) {
- // Если страница загрузилась то
- if (status == Status.control_request) {
- progressBar.setVisible(false);
- webView.setVisible(true);
- }
- if (status == Status.login_request) {
- // Авторизуемся
- label.setText("Загрузка интерфейса управления горелкой");
- login(webEngine);
- status = Status.control_request;
- }
- }
- }
- });
- primaryStage.setTitle("Консоль управления котельной");
- primaryStage.setScene(new Scene(root, 900, 600));
- primaryStage.show();
- }
- private void login(WebEngine webEngine) {
- webEngine.executeScript(setLogin);
- webEngine.executeScript(setPassword);
- webEngine.executeScript(btnLogin);
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- java.net.CookieManager manager = new java.net.CookieManager();
- java.net.CookieHandler.setDefault(manager);
- manager.getCookieStore().removeAll();
- //or
- java.net.CookieHandler.setDefault(new java.net.CookieManager());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement