当前位置: 代码迷 >> J2SE >> [Help] Java ToolTip解决方法
  详细解决方案

[Help] Java ToolTip解决方法

热度:98   发布时间:2016-04-24 14:27:15.0
[Help] Java ToolTip
请求高手们的帮助
图上生成了带点的曲线,现在鼠标移在点上需要有tooltip
代码如下:

for   (int   i   =   0;   i   <   values.size();   i++){
Double   dr   =   (Double)values.elementAt(i);
chart.getDataset().addElement(   i,   dr.doubleValue(),   0   );
}
这里用addElement添加了曲线上的点.   chart是自定义组件,代码如下.
========
import   java.awt.Container;
import   java.awt.Dimension;
import   java.awt.Event;
import   java.awt.Graphics;
import   java.awt.Graphics2D;
import   java.awt.Image;
import   java.awt.RenderingHints;
import   java.awt.event.ComponentAdapter;
import   java.awt.event.ComponentEvent;
import   java.awt.event.MouseEvent;
import   java.awt.event.MouseListener;
import   java.awt.event.MouseMotionListener;
import   java.awt.image.BufferedImage;
import   java.util.Vector;

import   javax.swing.ImageIcon;
import   javax.swing.JPanel;
import   javax.swing.event.EventListenerList;

public   class   DsChart   extends   CControl   implements   MouseListener,   MouseMotionListener
{
....

public   DsChart(){
initForm();
dataset   =   new   DsDataset(this);
bgImage   =   null;
....
}
class   DsChartPanel   extends   JPanel{
protected   Image   chartImage   =   null;

public   DsChartPanel(){
this.addComponentListener(new   ComponentAdapter()
{
public   void   componentResized(ComponentEvent   e)
{   chartImage   =   null;}});
}
......

}
private   DsChartPanel   m_this   =   new   DsChartPanel();
private   void   initForm(){
m_this.setSize(300,200);
m_this.setName( "chart1 ");
m_this.addMouseListener(this);
m_this.addMouseMotionListener(this);
/*
wfc   this.addOnClick(new   EventHandler(this.DsChart_click));
this.addOnMouseDown(new   MouseEventHandler(this.DsChart_mouseDown));
this.addOnResize(new   EventHandler(this.DsChart_resize));
*/
}

/**   Returns   the   {@link   DsDataset   }for   this   chart.*/
public   DsDataset   getDataset()
{
return   dataset;
}
=====

下面是   DsDataset   这个类
import   java.awt.BasicStroke;
import   java.awt.Graphics2D;
import   java.awt.Polygon;
import   java.awt.Stroke;
import   java.awt.Toolkit;
import   java.awt.geom.Point2D;
import   java.util.Vector;
public   class   DsDataset{
protected   Vector   pointSet;

/**   Construct   and   initialize   a   dataset   for   the   given   graph
*/
public   DsDataset(DsChart   xy){
pointSet   =   new   Vector();
......
}

/**Create   a   point   and   add   it   to   the   given   dataset*/
public   void   addElement(double   x,   double   y,   int   identifier){
addElement(new   DsXYPoint(x,   y),   identifier);
}


/**   Add   a   point   to   the   given   dataset*/
public   void   addElement(DsXYPoint   xy,   int   identifier){
Vector   points;

while   (pointSet.size()   <=   identifier){
  相关解决方案