mouseeventchart.java

来自「一个完整的」· Java 代码 · 共 48 行

JAVA
48
字号
package cn.com.fcsoft.chart.examples;
import cn.com.fcsoft.chart.*;

import java.awt.*;
import java.awt.event.*;


/**
 * This example catches mouse motion events.
 * @author meiqi.
 */
public class MouseEventChart extends BarChart implements MouseMotionListener {

	public void mouseMoved(MouseEvent e) {
		Point pos = new Point(e.getX(), e.getY());
		ChartSample bar = checkSelection(pos);
		if (bar != null) {
			System.out.println("mouse over bar: " + bar);
		}
	}
	
	public void mouseDragged(MouseEvent e) {
		Point pos = new Point(e.getX(), e.getY());
		ChartSample bar = checkSelection(pos);
		if (bar != null) {
			System.out.println("mouse dragged over bar: " + bar);
		}
	}
	
	public static void main(String[] argv) {
		// create the chart
		double[] values = new double[10];
		for (int i = 0; i < values.length; i++) {
			values[i] = Math.round(Math.random()*100);
		}
		MouseEventChart chart = new MouseEventChart();
		chart.setSampleCount(values.length);
		chart.setSampleValues(0, values);
		chart.setValueLinesOn(true);
		chart.addMouseMotionListener(chart);
		
		// display the chart
		Frame f = new Frame();
		f.add("Center", chart);
		f.setSize(400,300);
		f.show();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?