0

I want to draw a graph on each point of which there will be a button. When I will click the button, it will do something. Here's a link; I want my graph to look like this. Can anybody suggest me how to do it?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Mahmudur Rahman
  • 640
  • 1
  • 6
  • 23
  • *"Can anybody suggest me how to do it?"* See [Creating a GUI With JFC/Swing](http://docs.oracle.com/javase/tutorial/uiswing/) for details. This is 'too broad' to be covered on SO. – Andrew Thompson Mar 22 '15 at 08:54
  • http://docs.oracle.com/javafx/2/charts/line-chart.htm#CIHGBCFI i have found a way to draw the graph but how to add the buttons.can you tell me @AndrewThompson – Mahmudur Rahman Mar 22 '15 at 09:00
  • 1
    First, I wouldn't use actual `JButton` objects, but instead draw them using Java 2D. Then add a `MouseMotionListener` and a `MouseListener` to the component drawing the graph and check for clicks using the `MouseListener` and the pointer entering/leaving the `Shape` that comprises each 'button' using the other listener. If you get stuck, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example) of your attempt along with a *specific* question. – Andrew Thompson Mar 22 '15 at 09:21
  • Consider something like JFreeCharts – MadProgrammer Mar 22 '15 at 09:26

1 Answers1

1

Using JFreeChart, add a ChartMouseListener to your ChartPanel, as outlined here. In your implementation of chartMouseClicked() invoke Desktop#browse(), as illustrated here. In outline,

chartPanel.addChartMouseListener(new ChartMouseListener() {

    public void chartMouseClicked(ChartMouseEvent e) {
        // construct a URI based the result from e.getEntity()
        desktop.browse(uri);
    }

    public void chartMouseMoved(ChartMouseEvent e) {}

});
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045