Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.62 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package prepexamen1;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.BufferedWriter;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileReader;
  13. import java.io.FileWriter;
  14. import java.io.IOException;
  15. import java.nio.file.Files;
  16. import java.nio.file.Path;
  17. import java.nio.file.Paths;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.HashSet;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Set;
  25. import java.util.SortedMap;
  26. import java.util.TreeMap;
  27. import java.util.logging.Level;
  28. import java.util.logging.Logger;
  29. import javafx.application.Application;
  30. import javafx.beans.value.ChangeListener;
  31. import javafx.beans.value.ObservableValue;
  32. import javafx.collections.FXCollections;
  33. import javafx.collections.ObservableList;
  34. import javafx.event.ActionEvent;
  35. import javafx.event.EventHandler;
  36. import javafx.event.EventType;
  37. import javafx.scene.Scene;
  38. import javafx.scene.control.Button;
  39. import javafx.scene.control.Label;
  40. import javafx.scene.control.ListView;
  41. import javafx.scene.control.TextArea;
  42. import javafx.scene.control.TextField;
  43. import javafx.scene.layout.Border;
  44. import javafx.scene.layout.HBox;
  45. import javafx.scene.layout.StackPane;
  46. import javafx.scene.layout.VBox;
  47. import javafx.stage.FileChooser;
  48. import javafx.stage.FileChooser.ExtensionFilter;
  49. import javafx.stage.Stage;
  50. import javafx.stage.Window;
  51.  
  52. /**
  53. *
  54. * @author Robert-Edward
  55. */
  56. public class PrepExamen1 extends Application {
  57.  
  58. Button btn1 = new Button("Unde are filiale?");
  59. Button btn2 = new Button("Ce firme au filiale aici?");
  60. Button btn3 = new Button("Inregistrează");
  61. Button btn4 = new Button("Info autor aplicație");
  62. Button btn5 = new Button("Ce firme au min");
  63. TextArea txtArea = new TextArea(" ");
  64. TextField txtField = new TextField(" ");
  65. Label txtLabel = new Label(" filiale?");
  66.  
  67. String sirSelectat;
  68. String localitate;
  69. String firma;
  70.  
  71. Window mainStage = null;
  72.  
  73. Map<String, Set> map1 = new HashMap<String,Set>();
  74.  
  75. private ListView getListaSelectie1() {
  76. ListView<String> list1 = new ListView<>();
  77. list1.setPrefWidth(200);
  78. list1.setPrefHeight(200);
  79.  
  80. ObservableList<String> data = FXCollections.observableArrayList(
  81. "JavaWithLove", "HardBase", "Interface", "StaticState", "Dynamic",
  82. "SoftProgress");
  83. Collections.sort(data);
  84. list1.setItems(data);
  85. list1.getSelectionModel().selectedItemProperty()
  86. .addListener(new ChangeListener<String>() {
  87. int nr = 1;
  88.  
  89. public void changed(ObservableValue<? extends String> ov,
  90. final String oldvalue, final String newvalue) {
  91. firma = newvalue;
  92. }
  93. }
  94. );
  95. return list1;
  96. }
  97.  
  98. public File deschideFisier(boolean citire) {
  99. FileChooser fileChooser = new FileChooser();
  100. fileChooser.setTitle("Open Resource File");
  101. fileChooser.getExtensionFilters().addAll(
  102. new ExtensionFilter("Text Files", "*.txt"),
  103. new ExtensionFilter("Arbori", "*.arb"),
  104. new ExtensionFilter("All Files", "*.*"));
  105.  
  106. File selectedFile = citire ? fileChooser.showOpenDialog(mainStage)
  107. : fileChooser.showSaveDialog(mainStage);
  108. return selectedFile;
  109. }
  110.  
  111. private ListView getListaSelectie2() {
  112. ListView<String> list2 = new ListView<>();
  113. list2.setPrefWidth(200);
  114. list2.setPrefHeight(200);
  115. ObservableList<String> data = FXCollections.observableArrayList(
  116. "Suceava", "Falticeni", "Gura-Humorului", "Siret", "Botosani",
  117. "Tg. Neamt");
  118. Collections.sort(data);
  119. list2.setItems(data);
  120.  
  121. list2.getSelectionModel().selectedItemProperty()
  122. .addListener(new ChangeListener<String>() {
  123. int nr = 1;
  124.  
  125. public void changed(ObservableValue<? extends String> ov,
  126. final String oldvalue, final String newvalue) {
  127. localitate = newvalue;
  128. }
  129. }
  130. );
  131. return list2;
  132. }
  133.  
  134. public void afisareFisier()
  135. {
  136. BufferedReader in = null;
  137.  
  138. try
  139. {
  140. String str;
  141.  
  142. in = new BufferedReader (new FileReader("F:\\Facultate\\SDA\\PrepExamen1\\test.txt"));
  143. while((str = in.readLine()) != null )
  144. {
  145. txtArea.appendText(str);
  146. }
  147. } catch (IOException ex) {
  148. Logger.getLogger(PrepExamen1.class.getName()).log(Level.SEVERE, null, ex);
  149. }
  150. }
  151.  
  152. private HBox Box1() {
  153. HBox panou = new HBox(btn1, btn2, btn4);
  154. panou.setSpacing(20);
  155. return panou;
  156. }
  157.  
  158. private HBox Box2() {
  159. HBox panou = new HBox(getListaSelectie1(), getListaSelectie2(), btn3);
  160. panou.setSpacing(20);
  161. return panou;
  162. }
  163.  
  164. private HBox Box3() {
  165. HBox panou = new HBox(txtArea);
  166. panou.setSpacing(10);
  167. return panou;
  168. }
  169.  
  170. private HBox Box4()
  171. {
  172. HBox panou = new HBox(btn5, txtField, txtLabel);
  173. panou.setSpacing(10);
  174. panou.setTranslateX(440);
  175. panou.setTranslateY(-150);
  176. return panou;
  177. }
  178.  
  179. @Override
  180. public void start(Stage primaryStage) {
  181.  
  182. txtArea.setPrefWidth(800);
  183. btn1.setPrefWidth(200);
  184. btn2.setPrefWidth(200);
  185. btn3.setPrefWidth(200);
  186. btn4.setPrefWidth(200);
  187. txtField.setPrefWidth(50);
  188.  
  189. btn1.setOnAction(new EventHandler<ActionEvent>() {
  190.  
  191. @Override
  192. public void handle(ActionEvent event) {
  193. txtArea.appendText("\n" + firma + " are filiale in " + map1.get(firma));
  194.  
  195. }
  196. });
  197.  
  198. btn2.setOnAction(new EventHandler<ActionEvent>() {
  199.  
  200. @Override
  201. public void handle(ActionEvent event) {
  202. txtArea.appendText("\nIn " + localitate + " au filiale: ");
  203. for(Map.Entry<String, Set> entry : map1.entrySet())
  204. {
  205. if(entry.getValue().contains(localitate))
  206. txtArea.appendText(" " + entry.getKey() + ", ");
  207. }
  208.  
  209.  
  210. }
  211. });
  212.  
  213. btn3.setOnAction(new EventHandler<ActionEvent>() {
  214.  
  215. @Override
  216. public void handle(ActionEvent event) {
  217. if(!map1.containsKey(firma))
  218. {
  219. Set localitati = new HashSet();
  220. localitati.add(localitate);
  221. map1.put(firma, localitati);
  222. }
  223. else
  224. {
  225. map1.get(firma).add(localitate);
  226. }
  227.  
  228.  
  229. txtArea.appendText("\n" + firma + " -> " + localitate);
  230.  
  231. }
  232. });
  233.  
  234. btn4.setOnAction(new EventHandler<ActionEvent>() {
  235.  
  236. @Override
  237. public void handle(ActionEvent event) {
  238. txtArea.appendText("\n[Info autor aplicatie]\n");
  239.  
  240. }
  241. });
  242.  
  243. btn5.setOnAction(new EventHandler<ActionEvent>() {
  244.  
  245. @Override
  246. public void handle(ActionEvent event) {
  247. txtArea.appendText("\nUrmatoarele firme au mai mult de " + txtField.getText() + " filiale: ");
  248. for(Map.Entry<String, Set> entry : map1.entrySet())
  249. {
  250. if(entry.getValue().size() >= Integer.parseInt(txtField.getText()))
  251. {
  252. txtArea.appendText(" " + entry.getKey() + ", ");
  253. }
  254. }
  255. }
  256. });
  257.  
  258. HBox vid = new HBox();
  259. HBox vid1 = new HBox();
  260.  
  261. vid.setPrefHeight(10);
  262. vid1.setPrefHeight(10);
  263. VBox panouGrafic = new VBox(Box2(), Box4(), vid, Box1(), vid1, Box3());
  264. Scene scena = new Scene(panouGrafic, 650, 410);
  265. primaryStage.setScene(scena);
  266. primaryStage.setTitle("Subiect examen");
  267. primaryStage.show();
  268.  
  269. afisareFisier();
  270. }
  271.  
  272. /**
  273. * @param args the command line arguments
  274. */
  275. public static void main(String[] args) {
  276. launch(args);
  277. }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement