Class JGraph

All Implemented Interfaces:
MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class JGraph extends JPanel implements MouseListener
See Also:
  • Constructor Details

    • JGraph

      public JGraph(GraphSet gs)

      Creates a graph with the specified set.

      Parameters:
      gs - the set to be used
  • Method Details

    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • getToolTipText

      public String getToolTipText(MouseEvent event)
      This method is called automatically when the mouse is over the component. Based on the location of the event, we detect if we are over one of the circles. If so, we display some information relative to that circle If the mouse is not over any circle we return the tooltip of the component.
      Overrides:
      getToolTipText in class JComponent
    • setRoute

      public int setRoute(int r)

      Sets the highlighted route.

      The selected route is highlighted in the graph.

      Parameters:
      r - the route to be highlighted
      Returns:
      the previously set route
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • createAndShowUserInterface

      public void createAndShowUserInterface(int x, int y)

      Shows UI interface with graph with specified sizes.

      Parameters:
      x - width of window
      y - height of window
    • createAndShowUserInterface

      public void createAndShowUserInterface()
    • getScreenShot

      public BufferedImage getScreenShot(int width, int height)

      gets an image of the current graph.

      Parameters:
      width - the width of the screenshot in pixels
      height - the height of the screenshot in pixels
      Returns:
      the image
    • saveScreenshot

      public void saveScreenshot(String filename, int width, int height) throws IOException

      Writes a screenshot of the current graph into a jpeg file.

      Parameters:
      filename - name of the file to be written
      width - the width of the screenshot in pixels
      height - the height of the screenshot in pixels
      Throws:
      IOException - when writing file