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 javaprojectlast2;
- /**
- *
- * @author Fredrik
- */
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.*;
- import javafx.application.Application;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.UIManager;
- public class case0 extends Application {
- private final ArrayList<String> words1 = new ArrayList<String>();
- private final ArrayList<String> swe = new ArrayList<String>();
- private final ArrayList<String> eng = new ArrayList<String>();
- private final ArrayList<String> svar = new ArrayList<String>();
- private final ArrayList<Boolean> correct = new ArrayList<Boolean>();
- private final List<String> list = new ArrayList<String>();
- private final Scanner scanner = new Scanner(System.in);
- public case0() throws FileNotFoundException, IOException, NullPointerException {
- boolean language = false;
- String output = "";
- System.out.println("File open successfully!");
- boolean testeng;
- boolean testswe;
- int result = 1;
- int quit = 0;
- JFileChooser fc = new JFileChooser();
- // Show open dialog
- fc.showOpenDialog(null);
- File selFile = fc.getSelectedFile();
- // Show save dialog
- // fc.showSaveDialog(null);
- output = selFile.toString();
- System.out.println(output);
- UIManager.put("OptionPane.okButtonText", "Svenska");
- UIManager.put("OptionPane.cancelButtonText", "Engelska");
- int lang = JOptionPane.showConfirmDialog(null, "Välj vilket Språk du vill bli förhörd på!", null, JOptionPane.OK_CANCEL_OPTION);
- /* language = GUI2.display("Förhör", "Vilket språk vill du bli förhörd på?");
- System.out.println(language);*/
- while (quit != 1) {
- Scanner words = new Scanner(new File(output));
- boolean next = true;
- while (words.hasNextLine()) {
- String currLine = words.nextLine();
- words1.add(currLine);
- System.out.println(words1);
- //Delar orden för att kunna placera dem i olika arraylists
- // next = words.hasNextLine();
- }
- Collections.shuffle(words1);
- System.out.println(words1);
- String[] split = null;
- for (String currLine : words1) {
- currLine = currLine.trim();
- split = currLine.split(" - ");
- if (split.length == 2) {
- try {
- if (lang == JOptionPane.OK_OPTION) {
- // lägger till första ordet i split[0]
- swe.add(split[0]);
- //lägger till andra ordet i split[1]
- eng.add(split[1]);
- } else if (lang == JOptionPane.CANCEL_OPTION) {
- //lägger till första ordet i split[0]
- eng.add(split[0]);
- //lägger till andra ordet i split[1]
- swe.add(split[1]);
- }
- } catch (NullPointerException e) {
- System.out.println("kunde inte få tag på filen!");
- }
- }
- }
- if (swe.size() == eng.size()) {
- Collections.shuffle(swe);
- Collections.shuffle(eng);
- for (int i = 0; i < swe.size(); i++) {
- System.out.println("\n" + swe.get(i));
- String scn = scanner.nextLine();
- if (scn.equals(eng.get(i))) {
- correct.add(true);
- } else {
- correct.add(false);
- }
- }
- for (int i = 0; i < correct.size(); i++) {
- System.out.println(swe.get(i) + " : " + correct.get(i));
- }
- if (areAllTrue(correct)) {
- System.out.println("ALL ARE CORRECT!");
- } else {
- System.out.println("NOT ALL ARE CORRECT!");
- }
- }
- Object[][] rows = new Object[correct.size()][3];
- Object[] cols = {"Svenska", "Engelska", "Rätt/Fel"};
- for (int i = 0; i < correct.size(); i++) {
- rows[i][0] = swe.get(i);
- rows[i][1] = eng.get(i);
- rows[i][2] = correct.get(i);
- }
- JTable table = new JTable(rows, cols);
- //JOptionPane.showMessageDialog(null, new JScrollPane(table), "resultat");
- UIManager.put("OptionPane.okButtonText", "Stäng");
- JOptionPane.showMessageDialog(null, new JScrollPane(table));
- /* String[] buttons = {"Testa igen", "Testa de felaktiga orden", "Tillbaka till menyn"};
- int buttonsOut = JOptionPane.showOptionDialog(null, new JScrollPane(table), "Vad vill du göra?",
- JOptionPane.INFORMATION_MESSAGE, 0, null, buttons, buttons[2]); */
- quit = 1;
- /* if (buttonsOut == 0) {
- else if(buttonsOut == 1) {
- }
- else if(buttonsOut == 2) {
- }*/
- }
- }
- private void insertGlosa(String sweWord, String engWord) {
- }
- private static boolean areAllTrue(ArrayList<Boolean> al) {
- for (boolean b : al) {
- if (!b) { // om b inte är lika med al returnera false
- return false;
- }
- } //om det är sant returnera true
- return true;
- }
- @Override
- public void start(final Stage primaryStage) throws Exception {
- Stage window = primaryStage;
- primaryStage.setResizable(false);
- VBox layout = new VBox(10);
- layout.visibleProperty();
- layout.setAlignment(Pos.CENTER);
- // StackPane layout = new StackPane();
- window.setTitle("Välj vilket språk du vill bli förhörd på!");
- Button svenska = new Button("Svenska");
- Button engelska = new Button("Engelska");
- layout.getChildren().addAll(svenska, engelska);
- svenska.setOnAction(e -> {
- //layout.getChildren().removeAll(testaOrden, add, cancel);
- });
- engelska.setOnAction(e -> {
- //layout.getChildren().removeAll(testaOrden, add, cancel);
- });
- Scene scene = new Scene(layout, 500, 250);
- window.setScene(scene);
- window.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement