Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package prepexamen1;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.SortedMap;
- import java.util.TreeMap;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Application;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.event.EventType;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.ListView;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.Border;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.StackPane;
- import javafx.scene.layout.VBox;
- import javafx.stage.FileChooser;
- import javafx.stage.FileChooser.ExtensionFilter;
- import javafx.stage.Stage;
- import javafx.stage.Window;
- /**
- *
- * @author Robert-Edward
- */
- public class PrepExamen1 extends Application {
- Button btn1 = new Button("Unde are filiale?");
- Button btn2 = new Button("Ce firme au filiale aici?");
- Button btn3 = new Button("Inregistrează");
- Button btn4 = new Button("Info autor aplicație");
- Button btn5 = new Button("Ce firme au min");
- TextArea txtArea = new TextArea(" ");
- TextField txtField = new TextField(" ");
- Label txtLabel = new Label(" filiale?");
- String sirSelectat;
- String localitate;
- String firma;
- Window mainStage = null;
- Map<String, Set> map1 = new HashMap<String,Set>();
- private ListView getListaSelectie1() {
- ListView<String> list1 = new ListView<>();
- list1.setPrefWidth(200);
- list1.setPrefHeight(200);
- ObservableList<String> data = FXCollections.observableArrayList(
- "JavaWithLove", "HardBase", "Interface", "StaticState", "Dynamic",
- "SoftProgress");
- Collections.sort(data);
- list1.setItems(data);
- list1.getSelectionModel().selectedItemProperty()
- .addListener(new ChangeListener<String>() {
- int nr = 1;
- public void changed(ObservableValue<? extends String> ov,
- final String oldvalue, final String newvalue) {
- firma = newvalue;
- }
- }
- );
- return list1;
- }
- public File deschideFisier(boolean citire) {
- FileChooser fileChooser = new FileChooser();
- fileChooser.setTitle("Open Resource File");
- fileChooser.getExtensionFilters().addAll(
- new ExtensionFilter("Text Files", "*.txt"),
- new ExtensionFilter("Arbori", "*.arb"),
- new ExtensionFilter("All Files", "*.*"));
- File selectedFile = citire ? fileChooser.showOpenDialog(mainStage)
- : fileChooser.showSaveDialog(mainStage);
- return selectedFile;
- }
- private ListView getListaSelectie2() {
- ListView<String> list2 = new ListView<>();
- list2.setPrefWidth(200);
- list2.setPrefHeight(200);
- ObservableList<String> data = FXCollections.observableArrayList(
- "Suceava", "Falticeni", "Gura-Humorului", "Siret", "Botosani",
- "Tg. Neamt");
- Collections.sort(data);
- list2.setItems(data);
- list2.getSelectionModel().selectedItemProperty()
- .addListener(new ChangeListener<String>() {
- int nr = 1;
- public void changed(ObservableValue<? extends String> ov,
- final String oldvalue, final String newvalue) {
- localitate = newvalue;
- }
- }
- );
- return list2;
- }
- public void afisareFisier()
- {
- BufferedReader in = null;
- try
- {
- String str;
- in = new BufferedReader (new FileReader("F:\\Facultate\\SDA\\PrepExamen1\\test.txt"));
- while((str = in.readLine()) != null )
- {
- txtArea.appendText(str);
- }
- } catch (IOException ex) {
- Logger.getLogger(PrepExamen1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private HBox Box1() {
- HBox panou = new HBox(btn1, btn2, btn4);
- panou.setSpacing(20);
- return panou;
- }
- private HBox Box2() {
- HBox panou = new HBox(getListaSelectie1(), getListaSelectie2(), btn3);
- panou.setSpacing(20);
- return panou;
- }
- private HBox Box3() {
- HBox panou = new HBox(txtArea);
- panou.setSpacing(10);
- return panou;
- }
- private HBox Box4()
- {
- HBox panou = new HBox(btn5, txtField, txtLabel);
- panou.setSpacing(10);
- panou.setTranslateX(440);
- panou.setTranslateY(-150);
- return panou;
- }
- @Override
- public void start(Stage primaryStage) {
- txtArea.setPrefWidth(800);
- btn1.setPrefWidth(200);
- btn2.setPrefWidth(200);
- btn3.setPrefWidth(200);
- btn4.setPrefWidth(200);
- txtField.setPrefWidth(50);
- btn1.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- txtArea.appendText("\n" + firma + " are filiale in " + map1.get(firma));
- }
- });
- btn2.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- txtArea.appendText("\nIn " + localitate + " au filiale: ");
- for(Map.Entry<String, Set> entry : map1.entrySet())
- {
- if(entry.getValue().contains(localitate))
- txtArea.appendText(" " + entry.getKey() + ", ");
- }
- }
- });
- btn3.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- if(!map1.containsKey(firma))
- {
- Set localitati = new HashSet();
- localitati.add(localitate);
- map1.put(firma, localitati);
- }
- else
- {
- map1.get(firma).add(localitate);
- }
- txtArea.appendText("\n" + firma + " -> " + localitate);
- }
- });
- btn4.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- txtArea.appendText("\n[Info autor aplicatie]\n");
- }
- });
- btn5.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- txtArea.appendText("\nUrmatoarele firme au mai mult de " + txtField.getText() + " filiale: ");
- for(Map.Entry<String, Set> entry : map1.entrySet())
- {
- if(entry.getValue().size() >= Integer.parseInt(txtField.getText()))
- {
- txtArea.appendText(" " + entry.getKey() + ", ");
- }
- }
- }
- });
- HBox vid = new HBox();
- HBox vid1 = new HBox();
- vid.setPrefHeight(10);
- vid1.setPrefHeight(10);
- VBox panouGrafic = new VBox(Box2(), Box4(), vid, Box1(), vid1, Box3());
- Scene scena = new Scene(panouGrafic, 650, 410);
- primaryStage.setScene(scena);
- primaryStage.setTitle("Subiect examen");
- primaryStage.show();
- afisareFisier();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement