Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Graph.java
- package graphs;
- import java.io.File;
- 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 Graphs extends Application {
- @Override public void start(Stage stage) {
- stage.setTitle("Graph App");
- int firstFileCount=0;
- int secondFileCount=0;
- int thirdFileCount=0;
- int firstFileChar=0;
- int secondFileChar=0;
- int thirdFileChar=0;
- final NumberAxis xAxis = new NumberAxis();
- final NumberAxis yAxis = new NumberAxis();
- xAxis.setLabel("Numer lini");
- yAxis.setLabel("Długość lini");
- final LineChart<Number,Number> lineChart =
- new LineChart<Number,Number>(xAxis,yAxis);
- lineChart.setTitle("Wykres zależności długości lini od jej numeru w pliku tekstowym");
- LineCounter firstFile= new LineCounter(new File("C:\\Users\\202166\\Documents\\NetBeansProjects\\Graphs\\plik.txt"));
- firstFileCount=firstFile.readLines();
- firstFileChar=firstFile.readChars();
- LineCounter secondFile= new LineCounter(new File("C:\\Users\\202166\\Documents\\NetBeansProjects\\Graphs\\plik2.txt"));
- secondFileCount=secondFile.readLines();
- secondFileChar=secondFile.readChars();
- LineCounter thirdFile= new LineCounter(new File("C:\\Users\\202166\\Documents\\NetBeansProjects\\Graphs\\plik3.txt"));
- thirdFileCount=thirdFile.readLines();
- thirdFileChar=thirdFile.readLines();
- System.out.println(secondFileCount);
- XYChart.Series series = new XYChart.Series();
- //populating the series with data
- series.getData().add(new XYChart.Data(firstFileChar,firstFileCount));
- series.getData().add(new XYChart.Data(secondFileChar, secondFileCount));
- series.getData().add(new XYChart.Data(thirdFileChar, thirdFileCount));
- Scene scene = new Scene(lineChart,800,600);
- lineChart.getData().add(series);
- stage.setScene(scene);
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- //LineCounter.java
- package graphs;
- import java.io.File;
- import java.util.Scanner;
- public class LineCounter {
- private File file;
- private int lineCount=0;
- private int charCount=0;
- LineCounter(File file){
- this.file=file;
- }
- public int readLines(){
- try
- {
- Scanner myFile = new Scanner(file);
- while (myFile.hasNextLine())
- {
- lineCount++;
- myFile.nextLine();
- }
- }
- catch(Exception e)
- {
- System.out.println("Exception occured");
- }
- return lineCount;
- }
- public int readChars(){
- try{
- Scanner myFile= new Scanner(file);
- int wordsCount=0;
- while(myFile.hasNext()) {
- wordsCount++;
- String word = myFile.next();
- charCount += word.length();
- }
- } catch(Exception e){
- System.out.println("Exception occured");
- }
- return charCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement