Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. package aplikacja1;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import static javafx.application.Application.launch;
  7. import javafx.application.Application;
  8. import javafx.event.ActionEvent;
  9. import javafx.event.EventHandler;
  10. import javafx.geometry.Pos;
  11. import javafx.scene.Scene;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.control.Label;
  14. import javafx.scene.layout.StackPane;
  15. import javafx.scene.layout.GridPane;
  16. import javafx.stage.Stage;
  17. import javafx.scene.layout.VBox;
  18.  
  19. public class Aplikacja1 extends Application {
  20.  
  21. @Override
  22. public void start(Stage primaryStage) {
  23.  
  24. Label wynik = new Label("Połączono z bazą danych");
  25. Label err1 = new Label("Błąd połączenia z bazą danych");
  26. Label err2 = new Label("Błąd sterownika");
  27.  
  28. GridPane okno = new GridPane();
  29.  
  30. Button connect = new Button("Test");
  31. //connect.setText("Dane");
  32.  
  33. okno.add(connect,0,0);
  34.  
  35. connect.setOnAction(e->{
  36. okno.getChildren().remove(wynik);
  37. okno.getChildren().remove(err1);
  38. okno.getChildren().remove(err2);
  39.  
  40. Connection con;
  41. try{
  42. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  43. con = DriverManager.getConnection("jdbc:sqlserver://"+
  44. "153.19.7.13:1401;databaseName=kbohdanowicz;"+
  45. "user=kbohdanowicz;password=253933;");
  46. okno.add(wynik,100,100);
  47. con.close();
  48. }
  49. catch(SQLException error_polaczenie) {
  50. okno.add(err1,0,0);
  51. }
  52. catch(ClassNotFoundException error_sterownik) {
  53. okno.add(err2,0,0);
  54. }
  55. }
  56. );
  57.  
  58.  
  59. Button dane = new Button();
  60. dane.setText("Dane");
  61. dane.setOnAction(e-> {
  62. Label imNaz = new Label("Jakub Wędrowycz");
  63. }
  64. );
  65.  
  66.  
  67. VBox panel_lewy = new VBox();
  68. panel_lewy.setMinWidth(400);
  69. panel_lewy.setAlignment(Pos.CENTER_LEFT);
  70. okno.add(panel_lewy,0,0,1,4);
  71.  
  72. VBox panel_prawy = new VBox();
  73. panel_prawy.setMinWidth(400);
  74. panel_prawy.setAlignment(Pos.CENTER_RIGHT);
  75. okno.add(panel_prawy,0,0,1,4);
  76.  
  77. okno.getChildren().add(dane);
  78.  
  79.  
  80. Scene scena1 = new Scene(okno, 800, 600);
  81.  
  82. primaryStage.setTitle("Two Buttons");
  83. primaryStage.setScene(scena1);
  84. primaryStage.show();
  85. }
  86. public static void main(String[] args) {
  87. launch(args);
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement