Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package readingExcel;
  2.  
  3. import java.io.File;
  4.  
  5. import javafx.application.Application;
  6. import javafx.geometry.Pos;
  7. import javafx.geometry.Rectangle2D;
  8. import javafx.scene.Group;
  9. import javafx.scene.Scene;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.scene.layout.StackPane;
  12. import javafx.scene.paint.Color;
  13. import javafx.scene.shape.Circle;
  14. import javafx.scene.text.Font;
  15. import javafx.scene.text.FontWeight;
  16. import javafx.scene.text.Text;
  17. import javafx.stage.FileChooser;
  18. import javafx.stage.Screen;
  19. import javafx.stage.Stage;
  20. import javafx.event.ActionEvent;
  21. import javafx.event.EventHandler;
  22. import javafx.scene.control.Button;
  23. import javafx.scene.image.Image ;
  24. import javafx.scene.image.ImageView;
  25.  
  26.  
  27. public class GUI extends Application {
  28. private GridPane grid = new GridPane();
  29. private Button btn = new Button();
  30.  
  31. @Override
  32. public void start(Stage primaryStage) {
  33.  
  34. StackPane root = new StackPane();
  35.  
  36. setBackGround(root);
  37. addImage();
  38. addGrid(root);
  39. addBtn(primaryStage);
  40.  
  41. Scene scene = new Scene(root, 500, 400);
  42.  
  43. primaryStage.setTitle("Read Excel File");
  44. primaryStage.setScene(scene);
  45. primaryStage.show();
  46. }
  47.  
  48. public static void main(String[] args) {
  49. Application.launch(args);
  50. }
  51.  
  52. private void addGrid(StackPane root) {
  53.  
  54. grid.setAlignment(Pos.TOP_CENTER);
  55. grid.setHgap(10);
  56. grid.setVgap(10);
  57. grid.setMaxWidth(100);
  58. grid.setMaxHeight(100);
  59. grid.setPadding(new javafx.geometry.Insets(25, 25, 25, 25));
  60. Text text = new Text("Select Excel File : ");
  61. text.setFont(Font.font("Tahoma", FontWeight.NORMAL, 15));
  62. text.toFront();
  63. grid.add(text, 1, 5, 2, 1);
  64. root.getChildren().add(grid);
  65.  
  66. }
  67.  
  68. private void addBtn(final Stage primaryStage) {
  69.  
  70. btn.setText("Browse Files");
  71. btn.setOnAction(new EventHandler<ActionEvent>() {
  72.  
  73. @Override
  74. public void handle(ActionEvent event) {
  75. FileChooser fileChooser = new FileChooser();
  76. fileChooser.setTitle("Open Resource File");
  77. File file = fileChooser.showOpenDialog(primaryStage);
  78. // if (file != null) {
  79. // openFile(file);
  80. // }
  81. }
  82. });
  83.  
  84. grid.add(btn, 1, 5, 5, 8);
  85.  
  86.  
  87. }
  88.  
  89. private void openFile(File file){
  90.  
  91. }
  92. private void setBackGround(StackPane root) {
  93.  
  94. Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
  95.  
  96. double x = primaryScreenBounds.getWidth();
  97. double y = primaryScreenBounds.getHeight();
  98.  
  99. final Circle c = new Circle(x / 2, y / 2, 2 * x);
  100. c.setFill(Color.ORANGE);
  101. final Group g = new Group(c);
  102.  
  103. root.getChildren().add(g);
  104.  
  105. }
  106.  
  107. private void addImage(){
  108.  
  109. Image image = new Image("File:C:/Users/admin/Desktop/image.png");
  110. ImageView i = new ImageView(image);
  111. // i.setX(20);
  112. i.setFitHeight(130);
  113. i.setFitWidth(130);
  114. // i.setY(20);
  115. grid.add(i, 1,1);
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement