Advertisement
Trollfacedk

Untitled

Jan 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. // LOG.JAVA
  2. package Util;
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.TextArea;
  12. import javafx.scene.layout.StackPane;
  13. import javafx.stage.Stage;
  14.  
  15. public class Log {
  16.  
  17.  
  18. public static void Logger(String logText) {
  19.  
  20.  
  21. try (FileWriter fw = new FileWriter("log.pdf", true)){
  22. fw.write(logText);
  23. }
  24. catch(IOException exc){
  25. System.out.println("Du er jo en idiot!");
  26.  
  27. }
  28.  
  29. }
  30. public static List<String> fraLog() {
  31. List<String> list = new ArrayList<>();
  32. String s = "";
  33.  
  34. try (BufferedReader br = new BufferedReader(new FileReader("Log.pdf"))) {
  35. while ((s = br.readLine()) != null) {
  36. list.add(s + "\r\n");
  37. }
  38. } catch (IOException exc) {
  39. System.out.println("I/O Error: " + exc);
  40. }
  41. return list;
  42. }
  43. public static void abc(Stage secondStage){
  44. TextArea logText = new TextArea();
  45. for (String log : Log.fraLog()) {
  46. logText.setText(logText.getText() + log);
  47.  
  48. StackPane secondaryLayout = new StackPane();
  49. secondaryLayout.getChildren().add(logText);
  50. Scene secondScene = new Scene(secondaryLayout, 400, 375);
  51. secondStage.setTitle("Log");
  52. secondStage.setScene(secondScene);
  53. secondStage.show();
  54.  
  55. }
  56. }
  57. }
  58.  
  59.  
  60. Button btnLog = new Button("Log");
  61. grid.add(btnLog, 5, 5);
  62. btnLog.setOnAction(new EventHandler<ActionEvent>() {
  63. public void handle(ActionEvent event) {
  64. Log.abc(new Stage());
  65.  
  66. }
  67. });
  68.  
  69.  
  70. Button btnClog = new Button("Clog");
  71. grid.add(btnClog, 5, 6);
  72. btnClog.setOnAction(new EventHandler<ActionEvent>() {
  73. @Override
  74. public void handle(ActionEvent e) {
  75.  
  76. PrintWriter writer;
  77. try {
  78. writer = new PrintWriter("log.txt");
  79. writer.print(" ");
  80. writer.close();
  81. } catch (FileNotFoundException e1) {
  82.  
  83. e1.printStackTrace();
  84. }
  85.  
  86. }
  87. });
  88.  
  89.  
  90. package Logic;
  91.  
  92. import java.time.LocalDateTime;
  93.  
  94. import Util.Log;
  95.  
  96. public class Maths implements Calculator {
  97. LocalDateTime tid = LocalDateTime.now();
  98. Double svar, tal1,tal2;
  99. String icon;
  100.  
  101.  
  102. public double add(double a, double b) {
  103. double answer = a+b;
  104. svar=answer;
  105. icon = "+";
  106. tal1 = a; tal2 = b;
  107. String tilLog =tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
  108. Log.Logger(tilLog);
  109. return answer;
  110. }
  111.  
  112. public double subtract(double a, double b) {
  113. double answer = a-b;
  114. tal1 = a; tal2 = b;
  115. icon = "-";
  116. svar=answer;
  117. String tilLog =tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
  118. Log.Logger(tilLog);
  119. return answer;
  120.  
  121. }
  122.  
  123. public double multiply(double a, double b) {
  124. double answer = a*b;
  125. tal1 = a; tal2 = b;
  126. icon = "*";
  127. svar=answer;
  128. String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
  129. Log.Logger(tilLog);
  130. return answer;
  131.  
  132. }
  133.  
  134. public double divide(double a, double b) {
  135. double answer = a/b;
  136. tal1 = a; tal2 = b;
  137. icon = "/";
  138. svar=answer;
  139. String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar +"\r\n";
  140. Log.Logger(tilLog);
  141. return answer;
  142.  
  143. }
  144.  
  145. public double power(double a, double b){
  146. double answer =a;
  147.  
  148.  
  149. for (int x=2; x<=b; x++){
  150. answer *= a;
  151. }
  152. tal1 = a; tal2 = b;
  153. icon = "^";
  154. svar=answer;
  155. String tilLog = tid +": "+tal1+" "+icon+" "+tal2+" = "+svar + "\r\n";
  156. Log.Logger(tilLog);
  157. return answer;
  158.  
  159. }
  160.  
  161. public double rod(double inputB) {
  162. double answer;
  163. answer = Math.sqrt(inputB);
  164. svar=answer;
  165. String tilLog = tid +" "+tal1+" "+icon+" = "+svar + "\r\n";
  166. Log.Logger(tilLog);
  167. return answer;
  168. }
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement