2016-01-20 5 views
0

Я пишу программу, которая показывает форму волны с помощью Areachart.Когда я скомпилирую ее и запустил, она выглядит просто отлично, как показано ниже. Когда я выполняю файл .jar, я получаю полный другой вид моей формы волны.run as .jar приводит к другому виду

import java.io.BufferedReader; 
import java.io.FileReader; 
import java.util.concurrent.ConcurrentLinkedQueue; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javafx.animation.AnimationTimer; 
import javafx.animation.Timeline; 
import javafx.application.Application; 
import static javafx.application.Application.launch; 
import javafx.scene.Scene; 
import javafx.scene.chart.AreaChart; 
import javafx.scene.chart.NumberAxis; 
import javafx.scene.chart.XYChart.Data; 
import javafx.scene.chart.XYChart.Series; 
import javafx.stage.Stage; 


public class AreaChartSample extends Application { 

private static final int MAX_DATA_POINTS = 500; 

private Series series; 
private int xSeriesData = 0; 
private ConcurrentLinkedQueue<Number> dataQ = new ConcurrentLinkedQueue<>(); 
private ExecutorService executor; 
private AddToQueue addToQueue; 
private Timeline timeline2; 
private NumberAxis xAxis; 

private int time_counter=0; 
private int [] data_array=null; 

private void init(Stage primaryStage) { 

    String line,full_text=""; 

    try { 
     BufferedReader in = new BufferedReader(new FileReader("C:/testvideo/test.txt")); 

     while((line=in.readLine())!= null) 
     { 
      full_text+=line; 
     } 

     data_array=new int[full_text.length()]; 
     for(int i=0;i<full_text.length();i++) 
     { 
      data_array[i]=((int)(full_text.charAt(i)))-127; 
      // data_array[i]=((int)(full_text.charAt(i)))-300; 
     } 
    } catch (Exception e) { 
    } 



    xAxis = new NumberAxis(0,MAX_DATA_POINTS,MAX_DATA_POINTS/10); 
    xAxis.setForceZeroInRange(false); 
    xAxis.setAutoRanging(false); 

    NumberAxis yAxis = new NumberAxis(-127,127,1); 

    yAxis.setAutoRanging(false); 

    //-- Chart 
    final AreaChart<Number, Number> sc = new AreaChart<Number, Number>(xAxis, yAxis) { 
     // Override to remove symbols on each data point 
     @Override protected void dataItemAdded(Series<Number, Number> series, int itemIndex, Data<Number, Number> item) {} 
    }; 
    sc.setAnimated(false); 
    sc.setId("liveAreaChart"); 
    sc.setTitle("Animated Area Chart"); 

    //-- Chart Series 
    series = new AreaChart.Series<Number, Number>(); 
    series.setName("Area Chart Series"); 
    sc.getData().add(series); 

    primaryStage.setScene(new Scene(sc)); 
} 

@Override public void start(Stage primaryStage) throws Exception { 
    init(primaryStage); 
    primaryStage.show(); 

    //-- Prepare Executor Services 
    executor = Executors.newCachedThreadPool(); 
    addToQueue = new AddToQueue(); 
    executor.execute(addToQueue); 
    //-- Prepare Timeline 
    prepareTimeline(); 

    primaryStage.setOnCloseRequest(e -> { 
     executor.shutdown(); 
    }); 


} 

public static void main(String[] args) { 
    launch(args); 
} 

private class AddToQueue implements Runnable { 
    public void run() { 
     try { 
      // add a item of random data to queue 
      dataQ.add(data_array[time_counter]); 
      time_counter+=100; 
      Thread.sleep(10); 
      executor.execute(this); 
     } catch (InterruptedException ex) { 
      Logger.getLogger(AreaChartSample.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 
} 

//-- Timeline gets called in the JavaFX Main thread 
private void prepareTimeline() { 
    // Every frame to take any data from queue and add to chart 
    new AnimationTimer() { 
     @Override public void handle(long now) { 
      addDataToSeries(); 
     } 
    }.start(); 
} 

private void addDataToSeries() { 
    for (int i = 0; i < 20; i++) { //-- add 20 numbers to the plot+ 
     if (dataQ.isEmpty()) break; 
     Number y=dataQ.remove(); 
     series.getData().add(new AreaChart.Data(xSeriesData++, y)); 
     // System.out.println(y); 
    } 
    // remove points to keep us at no more than MAX_DATA_POINTS 
    if (series.getData().size() > MAX_DATA_POINTS) { 
     series.getData().remove(0, series.getData().size() - MAX_DATA_POINTS); 
    } 
    // update 
     xAxis.setLowerBound(xSeriesData-MAX_DATA_POINTS); 
     xAxis.setUpperBound(xSeriesData-1); 
} 

}

, когда я просто запустить его =>

enter image description here

, когда я выполнить сборки .jar файл (Windows 7 64 бит -> java8)

enter image description here

У меня нет абсолютно никакой идеи, почему это может случиться.

Обновление: здесь test.txt: http://expirebox.com/download/bf9be466e23c4c3d8f73f094f261dfbe.html

UPDATE2

Хорошо он должен иметь дело с чтением самой прикладной я изменить

data_array[i]=((int)(full_text.charAt(i)))-127; 

в

data_array[i]=data_array[i]=((int)('f'))-127; 

Это t он тот же в обеих версиях.

Есть ли другой способ, который мог бы читать корректно в обоих направлениях. Может быть, это связано с UTF8 или так?

+0

Что является содержимым файла 'C:/testvideo/test.txt'? – Andremoniy

+0

Считывает ли читатель точные значения строк в обоих случаях? – Berger

+0

Да, он использует тот же файл. Содержимое test.txt - это просто символы, такие как «yq ~ {z ~ {{~ t {zs {~ x {{z} w ~ {~ x {...." – user3776738

ответ

0

Это сделало трюк. Спасибо!

String fileName = "C:/testvideo/test.txt"; 
FileInputStream is = new FileInputStream(fileName); 
InputStreamReader isr = new InputStreamReader(is, "UTF-8"); 
BufferedReader in = new BufferedReader(isr); 
Смежные вопросы