无法在Java Swing中映射图像

问题描述 投票:1回答:1

我有一个名字为 ImageMapDemo7我想用这个程序映射一个图像,但我得到一个错误。我有所有的包。是否有任何 SampleXYDataset2 阶层 JFreeChart 还是没有?

代码是这样的。

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());
        }

    }

}

错误是这样的:

ImageMapDemo7.java:37: error: cannot find symbol
       final XYDataset data = new SampleXYDataset2();
                                  ^
  symbol:   class SampleXYDataset2
  location: class ImageMapDemo7
java imagemap
1个回答
1
投票

你需要在你的classpath中添加jfreechart-1.0.1-demo.jar。应该添加导入语句。Jar可以从这里下载 联系

© www.soinside.com 2019 - 2024. All rights reserved.