Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab4;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.control.Button;
- import javafx.scene.layout.StackPane;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.chart.LineChart;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.XYChart;
- import javafx.stage.Stage;
- public class Lab4 extends Application {
- static public int[] reads = new int[900];
- public static void read(String name){
- try {
- for(int i=0; i>=900;i++){
- reads[i] = 0;
- }
- File file = new File("C:\\Users\\Student\\Documents\\NetBeansProjects\\Lab4\\src\\lab4\\" + name);
- FileReader fileReader = new FileReader(file);
- BufferedReader bufferedReader = new BufferedReader(fileReader);
- StringBuffer stringBuffer = new StringBuffer();
- String line;
- int i= 0;
- while ((line = bufferedReader.readLine()) != null) {
- reads[i] = line.length();
- i += 1;
- }
- fileReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("zad4");
- //defining the axes
- final NumberAxis xAxis = new NumberAxis();
- final NumberAxis yAxis = new NumberAxis();
- xAxis.setLabel("Linia w pliku ");
- //creating the chart
- final LineChart<Number,Number> lineChart =
- new LineChart<Number,Number>(xAxis,yAxis);
- lineChart.setTitle("Ilosc znakow w linii");
- XYChart.Series series = new XYChart.Series();
- XYChart.Series series2 = new XYChart.Series();
- XYChart.Series series3 = new XYChart.Series();
- int i = 0;
- read("name.txt");
- series.setName("dziubdziub");
- series2.setName("Bohemian Rhapsody");
- series3.setName("Rap God");
- for(int item : reads){
- i+=1;
- series.getData().add(new XYChart.Data(i, item));
- if (item == 0) break;
- };
- read("name1.txt");
- i = 0;
- for(int item : reads){
- i+=1;
- series2.getData().add(new XYChart.Data(i, item));
- if (item == 0) break;
- };
- read("name2.txt");
- i = 0;
- for(int item : reads){
- i+=1;
- series3.getData().add(new XYChart.Data(i, item));
- if (item == 0) break;
- };
- Scene scene = new Scene(lineChart,1440,800);
- lineChart.getData().add(series);
- lineChart.getData().add(series2);
- lineChart.getData().add(series3);
- primaryStage.setScene(scene);
- primaryStage.show();
- StackPane root = new StackPane();
- primaryStage.setTitle("Hello World!");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement