Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为我的图表创建可运行线程?_Java_Multithreading_Swing_Runnable_Jtabbedpane - Fatal编程技术网

Java 如何为我的图表创建可运行线程?

Java 如何为我的图表创建可运行线程?,java,multithreading,swing,runnable,jtabbedpane,Java,Multithreading,Swing,Runnable,Jtabbedpane,我的程序已经启动,并且按照我想要的方式工作,但是现在我想在我的程序中实现Runnable,这样我就可以显示图表运行的每个选项卡。我该怎么做?我尝试过使用我以前使用过的方法,但我无法将其关联到我的程序中 public class Induction { final static String titles[] = {"A","B","C","S", "SH", "W"}; private final static TimeSeriesCollection all

我的程序已经启动,并且按照我想要的方式工作,但是现在我想在我的程序中实现Runnable,这样我就可以显示图表运行的每个选项卡。我该怎么做?我尝试过使用我以前使用过的方法,但我无法将其关联到我的程序中

    public class Induction {

      final static String titles[] = {"A","B","C","S", "SH", "W"};
      private final static TimeSeriesCollection all = new TimeSeriesCollection();
      static Day day = new Day(9,7,2014);

      private static TimeSeriesCollection createInduction() {

        for (String s : titles) {
            all.addSeries(new TimeSeries(s));
        }

        // while parsing the CSV file
        String zone = "/home/a002384/ECLIPSE/IN070914.CSV";
        TimeSeries ts = all.getSeries(zone);

        TreeMap<String, TreeMap<Integer, Integer[]>> zoneMap = new TreeMap<String, TreeMap<Integer, Integer[]>>();
        try{
            BufferedReader bufferedReader = new BufferedReader(new FileReader(zone));
            String line;
            try {
                // Read a line from the csv file until it reaches to the end of the file...
                while ((line = bufferedReader.readLine()) != null)
                {
                    // Parse a line of text in the CSV
                    String [] indData = line.split("\\,");
                    long millisecond = Long.parseLong(indData[0]);
                    String zones = indData[1];

                    // The millisecond value is the # of milliseconds since midnight
                    // From this, we can derive the hour and minute of the day
                    // as follows:
                    int secOfDay = (int) (millisecond / 1000);
                    int hrOfDay = secOfDay / 3600;
                    int minInHr = secOfDay % 3600 / 60;

                    // Obtain the induction rate TreeMap for the current zone
                    // If this is a "newly-encountered" zone, create a new TreeMap
                    TreeMap<Integer, Integer[]> hourCountsInZoneMap;
                    if (zoneMap.containsKey(zones))
                        hourCountsInZoneMap = zoneMap.get(zones);
                    else
                        hourCountsInZoneMap = new TreeMap<Integer, Integer[]>();

                    // Obtain the induction rate array for the current hour
                    // in the current zone.
                    // If this is a new hour in the current zone, create a
                    // new array, and initialize this array with all zeroes.
                    // The array is size 60, because there are 60 minutes in
                    // the hour. Each element in the array represents the
                    // induction rate for that minute
                    Integer [] indRatePerMinArray;
                    if (hourCountsInZoneMap.containsKey(hrOfDay))
                        indRatePerMinArray = hourCountsInZoneMap.get(hrOfDay);
                    else
                    {
                        indRatePerMinArray = new Integer[60];
                        Arrays.fill(indRatePerMinArray, 0);
                    }

                    // Increment the induction rate for the current minute
                    // by one. Each line in the csv file represents a
                    // single induction at a single point in time
                    indRatePerMinArray[minInHr]++;

                    // Add everything back into the TreeMaps if these are
                    // newly created.
                    if (!hourCountsInZoneMap.containsKey(hrOfDay))
                        hourCountsInZoneMap.put(hrOfDay, indRatePerMinArray);

                    if (!zoneMap.containsKey(zones))
                        zoneMap.put(zones, hourCountsInZoneMap);
                }
            }
            finally
            {
                bufferedReader.close();
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }

        // Iterate through all zones and print induction rates
        // for every minute into every hour by zone ...
        Iterator<String> zoneIT = zoneMap.keySet().iterator();
        while (zoneIT.hasNext())
        {
            String zones2 = zoneIT.next();
            TreeMap<Integer, Integer[]> hourCountsInZoneMap = zoneMap.get(zones2);
            System.out.println("ZONE " + zones2 + ":");
            Iterator<Integer> hrIT = hourCountsInZoneMap.keySet().iterator();
            while (hrIT.hasNext())
            {
                int hour = hrIT.next();
                Integer [] indRatePerMinArray = hourCountsInZoneMap.get(hour);
                for (int i = 0; i < indRatePerMinArray.length; i++)
                {
                    System.out.print(hour + ":");
                    System.out.print(i < 10 ? "0" + i : i);
                    System.out.println(" = " + indRatePerMinArray[i] + "induction(s)");
                }
            }
        }

        TimeSeries s1 = new TimeSeries("A");
        TreeMap<Integer, Integer[]> dayAZone = zoneMap.get("A");
        Iterator<Integer> hourIT = dayAZone.keySet().iterator();
        while (hourIT.hasNext())
        {
            Integer indHour = hourIT.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = dayAZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s1.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        TimeSeries s2 = new TimeSeries("B");
        TreeMap<Integer, Integer[]> dayBZone = zoneMap.get("B");
        Iterator<Integer> hourIT1 = dayBZone.keySet().iterator();
        while (hourIT1.hasNext())
        {
            Integer indHour = hourIT1.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = dayBZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s2.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        TimeSeries s3 = new TimeSeries("C");
        TreeMap<Integer, Integer[]> dayCZone = zoneMap.get("C");
        Iterator<Integer> hourIT2 = dayCZone.keySet().iterator();
        while (hourIT2.hasNext())
        {
            Integer indHour = hourIT2.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = dayCZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s3.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        TimeSeries s4 = new TimeSeries("S");
        TreeMap<Integer, Integer[]> daySZone = zoneMap.get("S");
        Iterator<Integer> hourIT3 = daySZone.keySet().iterator();
        while (hourIT3.hasNext())
        {
            Integer indHour = hourIT3.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = daySZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s4.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        TimeSeries s5 = new TimeSeries("SH");
        TreeMap<Integer, Integer[]> daySHZone = zoneMap.get("SH");
        Iterator<Integer> hourIT4 = daySHZone.keySet().iterator();
        while (hourIT4.hasNext())
        {
            Integer indHour = hourIT4.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = daySHZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s5.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        TimeSeries s6 = new TimeSeries("W");
        TreeMap<Integer, Integer[]> dayWZone = zoneMap.get("W");
        Iterator<Integer> hourIT5 = dayWZone.keySet().iterator();
        while (hourIT5.hasNext())
        {
            Integer indHour = hourIT5.next();
            Hour hour = new Hour(indHour, day);
            Integer [] indMins = dayWZone.get(indHour);
            for (int i = 0; i < 60; i++)
                s6.addOrUpdate(new Minute(i, hour), indMins[i]);
                System.out.println(zoneMap);
        }

        all.addSeries(s1);
        all.addSeries(s2);
        all.addSeries(s3);
        all.addSeries(s4);
        all.addSeries(s5);
        all.addSeries(s6);

        return all;

    }

    private static ChartPanel createPane(String title) {

        TimeSeriesCollection dataset = new ``TimeSeriesCollection(all.getSeries(title));
        int j = 0;
        JFreeChart chart = ChartFactory.createXYBarChart(
                "Induction Chart Zone ", 
                "Hour", 
                true, 
                "Inductions Per Minute", 
                dataset, 
                PlotOrientation.VERTICAL, 
                false, 
                true, 
                false
                );

        XYPlot plot = (XYPlot)chart.getPlot();
        XYBarRenderer renderer = (XYBarRenderer)plot.getRenderer();
        renderer.setBarPainter(new StandardXYBarPainter());
        renderer.setDrawBarOutline(false);

        // Set an induction of 30 per minute...
        Marker target = new ValueMarker(30);
        target.setPaint(java.awt.Color.blue);
        target.setLabel("Rate");
        plot.addRangeMarker(target);

        return new ChartPanel(chart);

    }

public static void main(String[] args) {
    createInduction();
    final JFrame frame = new JFrame("Induction Zone Chart");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JTabbedPane jtp = new JTabbedPane();

    final int j = 0;
    jtp.add(titles[j], createPane("A"));
    jtp.add(titles[j+1], createPane("B"));
    jtp.add(titles[j+2], createPane("C"));
    jtp.add(titles[j+3], createPane("S"));
    jtp.add(titles[j+4], createPane("SH"));
    jtp.add(titles[j+5], createPane("W"));
    for (String s : titles) {
        jtp.add(createPane(s));
    }
    jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    ChartPanel chart = null;

    for (int i = 0; i < titles.length; i++) 
    {
        chart = createPane(titles[i].substring(1, titles[i].length()));
    }

    final JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JButton(new AbstractAction("Update") {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            frame.repaint();
        }
    }));


    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            String tabTitle = sourceTabbedPane.getTitleAt(index);
            createPane(tabTitle.substring(0, tabTitle.length()));
            System.out.println("Source to " + tabTitle);
        }
    };

    while (jtp.getTabCount() > 6)
        jtp.remove(6);

    jtp.addChangeListener(changeListener);
    frame.add(jtp, BorderLayout.CENTER);
    frame.add(p, BorderLayout.SOUTH);

    frame.setPreferredSize(new Dimension(1000, 600));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
公共课堂导入{
最终静态字符串标题[]={“A”、“B”、“C”、“S”、“SH”、“W”};
private final static TimeSeriesCollection all=新TimeSeriesCollection();
静态日=新的一天(9,72014);
私有静态时间体验集合createImportion(){
用于(字符串s:标题){
所有.addSeries(新的时间序列);
}
//在分析CSV文件时
String zone=“/home/a002384/ECLIPSE/IN070914.CSV”;
TimeSeries ts=all.getSeries(区域);
TreeMap zoneMap=新的TreeMap();
试一试{
BufferedReader BufferedReader=新的BufferedReader(新文件读取器(区域));
弦线;
试一试{
//从csv文件中读取一行,直到它到达文件末尾。。。
而((line=bufferedReader.readLine())!=null)
{
//解析CSV中的一行文本
字符串[]indData=line.split(“\\,”);
long毫秒=long.parseLong(indData[0]);
字符串区域=indData[1];
//毫秒值是自午夜起的毫秒数
//由此,我们可以得出一天中的小时和分钟
//详情如下:
int secOfDay=(int)(毫秒/1000);
inthrofday=secOfDay/3600;
int minInHr=第二天%3600/60;
//获取当前区域的感应率树图
//如果这是一个“新遇到”的区域,请创建一个新的树状图
树映射小时计数分区映射;
if(区域映射容器(区域))
hourCountsInZoneMap=zoneMap.get(区域);
其他的
hourCountsInZoneMap=新树映射();
//获取当前小时的感应率数组
//在当前区域中。
//如果这是当前区域中的新小时,请创建
//新建数组,并用全零初始化此数组。
//阵列的大小为60,因为其中有60分钟
//小时。数组中的每个元素表示
//那一分钟的入职率
整数[]indRatePerMinArray;
如果(小时计数分区容器(hrOfDay))
indRatePerMinArray=小时计数区域映射获取(hrOfDay);
其他的
{
indRatePerMinArray=新整数[60];
数组。填充(indRatePerMinArray,0);
}
//增加当前分钟的诱导率
//csv文件中的每一行代表一个
//在单一时间点进行单一感应
indRatePerMinArray[minInHr]+;
//将所有内容添加回树状图(如果有)
//新创建的。
如果(!hourCountsInZoneMap.Containeskey(hrOfDay))
小时计数分区放置(hrOfDay,indRatePerMinArray);
如果(!zoneMap.containsKey(分区))
区域映射放置(区域、小时计数区域映射);
}
}
最后
{
bufferedReader.close();
}
}
捕获(例外e){
e、 printStackTrace();
}
//迭代所有区域并打印导入率
//每分每秒,每小时,每一个区域。。。
迭代器zoneIT=zoneMap.keySet().Iterator();
while(zoneIT.hasNext())
{
字符串zones2=zoneIT.next();
TreeMap hourCountsInZoneMap=zoneMap.get(zones2);
System.out.println(“区域”+区域2+:”);
迭代器hrIT=hourCountsInZoneMap.keySet().Iterator();
while(hrIT.hasNext())
{
inthour=hrIT.next();
整数[]indRatePerMinArray=hourCountsInZoneMap.get(小时);
for(int i=0;i