Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aplikacja1;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import static javafx.application.Application.launch;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.layout.StackPane;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- import javafx.scene.layout.VBox;
- public class Aplikacja1 extends Application {
- @Override
- public void start(Stage primaryStage) {
- Label wynik = new Label("Połączono z bazą danych");
- Label err1 = new Label("Błąd połączenia z bazą danych");
- Label err2 = new Label("Błąd sterownika");
- GridPane okno = new GridPane();
- Button connect = new Button("Test");
- //connect.setText("Dane");
- okno.add(connect,0,0);
- connect.setOnAction(e->{
- okno.getChildren().remove(wynik);
- okno.getChildren().remove(err1);
- okno.getChildren().remove(err2);
- Connection con;
- try{
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=kbohdanowicz;"+
- "user=kbohdanowicz;password=253933;");
- okno.add(wynik,100,100);
- con.close();
- }
- catch(SQLException error_polaczenie) {
- okno.add(err1,0,0);
- }
- catch(ClassNotFoundException error_sterownik) {
- okno.add(err2,0,0);
- }
- }
- );
- Button dane = new Button();
- dane.setText("Dane");
- dane.setOnAction(e-> {
- Label imNaz = new Label("Jakub Wędrowycz");
- }
- );
- VBox panel_lewy = new VBox();
- panel_lewy.setMinWidth(400);
- panel_lewy.setAlignment(Pos.CENTER_LEFT);
- okno.add(panel_lewy,0,0,1,4);
- VBox panel_prawy = new VBox();
- panel_prawy.setMinWidth(400);
- panel_prawy.setAlignment(Pos.CENTER_RIGHT);
- okno.add(panel_prawy,0,0,1,4);
- okno.getChildren().add(dane);
- Scene scena1 = new Scene(okno, 800, 600);
- primaryStage.setTitle("Two Buttons");
- primaryStage.setScene(scena1);
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement