Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. package application;
  2.  
  3.  
  4. import javafx.scene.Scene;
  5. import javafx.stage.Stage;
  6. import javafx.scene.text.Font;
  7. import javafx.scene.text.Text;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.TextArea;
  10. import javafx.scene.Group;
  11. import javafx.scene.Node;
  12.  
  13. import java.awt.TextField;
  14. import java.sql.Connection;
  15. import java.sql.DriverManager;
  16. import java.sql.ResultSet;
  17. import java.sql.SQLException;
  18. import javafx.geometry.Insets;
  19. import javafx.geometry.Pos;
  20. import javafx.scene.layout.GridPane;
  21.  
  22. import com.mysql.jdbc.PreparedStatement;
  23.  
  24.  
  25. public class HomePage extends Stage {
  26.     public HomePage(String userName) {
  27.        
  28.        
  29.         // start connecting to database
  30.         try {
  31.             Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/Online_Book_Store?useSSL=false", "root", "ahmed666" );
  32.             PreparedStatement p = (PreparedStatement) con.prepareStatement("select USER_NAME from USERS");
  33.             ResultSet rs = p.executeQuery();
  34.              while (rs.next()) {
  35.                     String name = rs.getString("USER_NAME");
  36.                     System.out.println(name);
  37.                 }
  38.            
  39.            
  40.            
  41.         } catch (SQLException e) {
  42.             // TODO Auto-generated catch block
  43.             e.printStackTrace();
  44.         }
  45.        
  46.        
  47.        
  48.         // Text Area for search label
  49.         TextField search = new TextField("");
  50.        
  51.         //search button
  52.         Button buttonFour = new Button("Search by name");
  53.        
  54.        
  55.        
  56.        
  57.         //search button
  58.         Button buttonFive = new Button("Search by ISBN");
  59.        
  60.        
  61.        
  62.         //personal info button
  63.         Button buttonOne = new Button("Edit personal info");
  64.        
  65.        
  66.         //Shopping cart button
  67.         Button buttonTwo = new Button("Shopping cart");
  68.        
  69.         //Shopping cart button
  70.         Button buttonThree = new Button("Logout");
  71.        
  72.        
  73.         //Styling nodes  
  74.         buttonOne.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
  75.         buttonTwo.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
  76.         buttonThree.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
  77.         buttonFour.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
  78.         buttonFive.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
  79.    
  80.        
  81.        
  82.         //Creating a Grid Pane
  83.         GridPane gridPane = new GridPane();    
  84.          
  85.         //Setting size for the pane  
  86.         gridPane.setMinSize(800, 600);
  87.            
  88.         //Setting the padding  
  89.         gridPane.setPadding(new Insets(10, 10, 10, 10));
  90.          
  91.         //Setting the vertical and horizontal gaps between the columns
  92.         gridPane.setVgap(30);
  93.         gridPane.setHgap(30);      
  94.          
  95.         //Setting the Grid alignment
  96.         gridPane.setAlignment(Pos.CENTER);
  97.            
  98.         //Arranging all the nodes in the grid
  99.         gridPane.add(buttonFive, 0, 0);
  100.         gridPane.add(buttonFour, 2, 0);      
  101.         gridPane.add(buttonOne, 2, 1);
  102.         gridPane.add(buttonTwo, 2, 2);
  103.         gridPane.add(buttonThree, 2, 3);
  104.         gridPane.add(search, 1, 0);
  105.        
  106.        
  107.        
  108.        
  109.        
  110.        
  111.        
  112.        
  113.        
  114.        
  115.         Scene scene = new Scene(gridPane);
  116.        
  117.         scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
  118.         setScene(scene);
  119.         setTitle(userName);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement