Advertisement
Guest User

Untitled

a guest
May 6th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 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 javaprojectlast2;
  7.  
  8.  
  9. /**
  10. *
  11. * @author Fredrik
  12. */
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15. import java.io.IOException;
  16. import java.util.*;
  17. import javafx.application.Application;
  18. import javafx.geometry.Pos;
  19. import javafx.scene.Scene;
  20. import javafx.scene.control.Button;
  21. import javafx.scene.layout.VBox;
  22. import javafx.stage.Stage;
  23. import javax.swing.JFileChooser;
  24. import javax.swing.JOptionPane;
  25. import javax.swing.JScrollPane;
  26. import javax.swing.JTable;
  27. import javax.swing.UIManager;
  28.  
  29. public class case0 extends Application {
  30.  
  31. private final ArrayList<String> words1 = new ArrayList<String>();
  32. private final ArrayList<String> swe = new ArrayList<String>();
  33. private final ArrayList<String> eng = new ArrayList<String>();
  34. private final ArrayList<String> svar = new ArrayList<String>();
  35. private final ArrayList<Boolean> correct = new ArrayList<Boolean>();
  36. private final List<String> list = new ArrayList<String>();
  37. private final Scanner scanner = new Scanner(System.in);
  38.  
  39. public case0() throws FileNotFoundException, IOException, NullPointerException {
  40. boolean language = false;
  41.  
  42. String output = "";
  43. System.out.println("File open successfully!");
  44. boolean testeng;
  45. boolean testswe;
  46. int result = 1;
  47. int quit = 0;
  48.  
  49. JFileChooser fc = new JFileChooser();
  50. // Show open dialog
  51. fc.showOpenDialog(null);
  52. File selFile = fc.getSelectedFile();
  53. // Show save dialog
  54. // fc.showSaveDialog(null);
  55. output = selFile.toString();
  56. System.out.println(output);
  57.  
  58.  
  59. UIManager.put("OptionPane.okButtonText", "Svenska");
  60. UIManager.put("OptionPane.cancelButtonText", "Engelska");
  61. int lang = JOptionPane.showConfirmDialog(null, "Välj vilket Språk du vill bli förhörd på!", null, JOptionPane.OK_CANCEL_OPTION);
  62. /* language = GUI2.display("Förhör", "Vilket språk vill du bli förhörd på?");
  63. System.out.println(language);*/
  64.  
  65.  
  66. while (quit != 1) {
  67. Scanner words = new Scanner(new File(output));
  68. boolean next = true;
  69. while (words.hasNextLine()) {
  70.  
  71. String currLine = words.nextLine();
  72. words1.add(currLine);
  73. System.out.println(words1);
  74. //Delar orden för att kunna placera dem i olika arraylists
  75. // next = words.hasNextLine();
  76. }
  77.  
  78. Collections.shuffle(words1);
  79. System.out.println(words1);
  80. String[] split = null;
  81.  
  82. for (String currLine : words1) {
  83. currLine = currLine.trim();
  84. split = currLine.split(" - ");
  85.  
  86. if (split.length == 2) {
  87.  
  88. try {
  89. if (lang == JOptionPane.OK_OPTION) {
  90. // lägger till första ordet i split[0]
  91. swe.add(split[0]);
  92. //lägger till andra ordet i split[1]
  93. eng.add(split[1]);
  94.  
  95. } else if (lang == JOptionPane.CANCEL_OPTION) {
  96. //lägger till första ordet i split[0]
  97. eng.add(split[0]);
  98. //lägger till andra ordet i split[1]
  99. swe.add(split[1]);
  100.  
  101. }
  102. } catch (NullPointerException e) {
  103. System.out.println("kunde inte få tag på filen!");
  104. }
  105. }
  106. }
  107. if (swe.size() == eng.size()) {
  108. Collections.shuffle(swe);
  109. Collections.shuffle(eng);
  110. for (int i = 0; i < swe.size(); i++) {
  111. System.out.println("\n" + swe.get(i));
  112.  
  113. String scn = scanner.nextLine();
  114. if (scn.equals(eng.get(i))) {
  115. correct.add(true);
  116. } else {
  117. correct.add(false);
  118. }
  119. }
  120.  
  121. for (int i = 0; i < correct.size(); i++) {
  122. System.out.println(swe.get(i) + " : " + correct.get(i));
  123. }
  124.  
  125. if (areAllTrue(correct)) {
  126. System.out.println("ALL ARE CORRECT!");
  127. } else {
  128. System.out.println("NOT ALL ARE CORRECT!");
  129. }
  130. }
  131. Object[][] rows = new Object[correct.size()][3];
  132. Object[] cols = {"Svenska", "Engelska", "Rätt/Fel"};
  133.  
  134. for (int i = 0; i < correct.size(); i++) {
  135. rows[i][0] = swe.get(i);
  136. rows[i][1] = eng.get(i);
  137. rows[i][2] = correct.get(i);
  138. }
  139. JTable table = new JTable(rows, cols);
  140. //JOptionPane.showMessageDialog(null, new JScrollPane(table), "resultat");
  141. UIManager.put("OptionPane.okButtonText", "Stäng");
  142. JOptionPane.showMessageDialog(null, new JScrollPane(table));
  143.  
  144. /* String[] buttons = {"Testa igen", "Testa de felaktiga orden", "Tillbaka till menyn"};
  145. int buttonsOut = JOptionPane.showOptionDialog(null, new JScrollPane(table), "Vad vill du göra?",
  146. JOptionPane.INFORMATION_MESSAGE, 0, null, buttons, buttons[2]); */
  147. quit = 1;
  148. /* if (buttonsOut == 0) {
  149.  
  150. else if(buttonsOut == 1) {
  151.  
  152.  
  153. }
  154. else if(buttonsOut == 2) {
  155.  
  156.  
  157. }*/
  158.  
  159. }
  160.  
  161. }
  162.  
  163. private void insertGlosa(String sweWord, String engWord) {
  164.  
  165. }
  166.  
  167. private static boolean areAllTrue(ArrayList<Boolean> al) {
  168. for (boolean b : al) {
  169. if (!b) { // om b inte är lika med al returnera false
  170. return false;
  171. }
  172. } //om det är sant returnera true
  173. return true;
  174. }
  175.  
  176. @Override
  177. public void start(final Stage primaryStage) throws Exception {
  178. Stage window = primaryStage;
  179. primaryStage.setResizable(false);
  180. VBox layout = new VBox(10);
  181. layout.visibleProperty();
  182. layout.setAlignment(Pos.CENTER);
  183. // StackPane layout = new StackPane();
  184. window.setTitle("Välj vilket språk du vill bli förhörd på!");
  185.  
  186. Button svenska = new Button("Svenska");
  187. Button engelska = new Button("Engelska");
  188. layout.getChildren().addAll(svenska, engelska);
  189. svenska.setOnAction(e -> {
  190. //layout.getChildren().removeAll(testaOrden, add, cancel);
  191.  
  192. });
  193. engelska.setOnAction(e -> {
  194. //layout.getChildren().removeAll(testaOrden, add, cancel);
  195.  
  196. });
  197. Scene scene = new Scene(layout, 500, 250);
  198. window.setScene(scene);
  199. window.show();
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement