Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. @FXML
  2. Button bt1;
  3.  
  4. @FXML
  5. Button bt2;
  6.  
  7.  
  8. public void bt1_click(ActionEvent actionEvent) throws Exception {
  9. PostLP.login = "логин1";
  10. PostLP.password = "пароль1";
  11. Application ap = new Boiler_control();
  12. ap.start(new Stage());
  13. }
  14.  
  15.  
  16. public void bt2_click(ActionEvent actionEvent) throws Exception {
  17. PostLP.login = "логин2";
  18. PostLP.password = "пароль2";
  19. Application ap = new Boiler_control();
  20. ap.start(new Stage());
  21. }
  22.  
  23. package boilercontrolpanel;
  24.  
  25. import javafx.application.Application;
  26. import javafx.beans.value.ChangeListener;
  27. import javafx.beans.value.ObservableValue;
  28. import javafx.concurrent.Worker.State;
  29. import javafx.fxml.FXMLLoader;
  30. import javafx.scene.Parent;
  31. import javafx.scene.Scene;
  32. import javafx.scene.control.Label;
  33. import javafx.scene.control.ProgressBar;
  34. import javafx.scene.web.WebEngine;
  35. import javafx.scene.web.WebView;
  36. import javafx.stage.Stage;
  37.  
  38. public class Boiler_control extends Application {
  39.  
  40. public enum Status {
  41. login_request,
  42. control_request,
  43. }
  44.  
  45. Status status = Status.login_request;
  46.  
  47. String setLogin = "document.getElementsByName('username')[0].value='" + PostLP.login + "';";
  48. String setPassword = "document.getElementsByName('password')[0].value='" + PostLP.password + "';";
  49. String btnLogin = "document.getElementById('btnLogin').click();";
  50.  
  51.  
  52.  
  53. @Override
  54. public void start(Stage primaryStage) throws Exception{
  55. Parent root = FXMLLoader.load(getClass().getResource("boiler_control.fxml"));
  56.  
  57. WebView webView = (WebView) root.lookup("#web_view");
  58. webView.setVisible(true);
  59. WebEngine webEngine = webView.getEngine();
  60. webEngine
  61.  
  62. webEngine.load("https://сайт");
  63.  
  64. Label label = (Label) root.lookup("#label");
  65.  
  66. ProgressBar progressBar = (ProgressBar) root.lookup("#prbar");
  67.  
  68. progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty());
  69.  
  70. webEngine.getLoadWorker().stateProperty().addListener(
  71. new ChangeListener<State>() {
  72. @Override
  73. public void changed(ObservableValue ov, State oldState, State newState) {
  74. if (newState == State.SUCCEEDED) {
  75. // Если страница загрузилась то
  76. if (status == Status.control_request) {
  77. progressBar.setVisible(false);
  78. webView.setVisible(true);
  79. }
  80.  
  81. if (status == Status.login_request) {
  82. // Авторизуемся
  83. label.setText("Загрузка интерфейса управления горелкой");
  84. login(webEngine);
  85. status = Status.control_request;
  86. }
  87.  
  88. }
  89. }
  90. });
  91.  
  92. primaryStage.setTitle("Консоль управления котельной");
  93. primaryStage.setScene(new Scene(root, 900, 600));
  94. primaryStage.show();
  95. }
  96.  
  97. private void login(WebEngine webEngine) {
  98. webEngine.executeScript(setLogin);
  99. webEngine.executeScript(setPassword);
  100. webEngine.executeScript(btnLogin);
  101. }
  102.  
  103.  
  104. public static void main(String[] args) {
  105. launch(args);
  106. }
  107. }
  108.  
  109. java.net.CookieManager manager = new java.net.CookieManager();
  110. java.net.CookieHandler.setDefault(manager);
  111.  
  112. manager.getCookieStore().removeAll();
  113.  
  114. //or
  115.  
  116. java.net.CookieHandler.setDefault(new java.net.CookieManager());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement