Not able to map image in Java Swing

。_饼干妹妹 提交于 2020-04-30 02:22:31

问题


I have a class with the name of ImageMapDemo7, and I want to map an image with this program; but I'm getting an error. I have all packages. Is there any SampleXYDataset2 class in JFreeChart or not?

The code is this:

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;

/**
 * A demo showing how to create an HTML image map for a scatter plot.
 *
 */
public class ImageMapDemo7 {

    /**
     * Default constructor.
     */
    public ImageMapDemo7() {
        super();
    }


    public static void main(final String[] args) {

       final XYDataset data = new SampleXYDataset2();
        final JFreeChart chart = ChartFactory.createScatterPlot(
            "Scatter Plot Demo",
            "X", "Y", 
            data, 
            PlotOrientation.VERTICAL,
            true, 
            true, 
            false
        );
//      final NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        chart.setBackgroundPaint(java.awt.Color.white);

        // save it to an image

       try {
            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            final File file1 = new File("image1.jpg");
            ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

            // write an HTML page incorporating the image with an image map
            final File file2 = new File("scatter100.html");
            final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
            final PrintWriter writer = new PrintWriter(out);
            writer.println("<HTML>");
            writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
            writer.println("<BODY>");
//            ChartUtilities.writeImageMap(writer, "chart", info);
            writer.println("<IMG SRC=\"image1.jpg\" "
                           + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
            writer.println("</BODY>");
            writer.println("</HTML>");
            writer.close();

        }
        catch (IOException e) {
            System.out.println(e.toString());
        }

    }

}

The error is this:

ImageMapDemo7.java:37: error: cannot find symbol
       final XYDataset data = new SampleXYDataset2();
                                  ^
  symbol:   class SampleXYDataset2
  location: class ImageMapDemo7

回答1:


You need to add jfreechart-1.0.1-demo.jar in your classpath. Import statement should be added. Jar can be downloaded from this link



来源:https://stackoverflow.com/questions/19464319/not-able-to-map-image-in-java-swing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!