0% found this document useful (0 votes)
68 views

Graph 2 D

Graph2D is a Java class that allows users to draw graphics like strings, points, lines, polygons, and arcs in a 2D space. It defines fields for colors, fonts, and dimensions. Constructors allow setting the dimensions and properties. Methods support drawing basic shapes with options for colors and thickness, as well as setting properties, clearing the graph, and showing/hiding mouse position and axes.

Uploaded by

Víctor Manises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Graph 2 D

Graph2D is a Java class that allows users to draw graphics like strings, points, lines, polygons, and arcs in a 2D space. It defines fields for colors, fonts, and dimensions. Constructors allow setting the dimensions and properties. Methods support drawing basic shapes with options for colors and thickness, as well as setting properties, clearing the graph, and showing/hiding mouse position and axes.

Uploaded by

Víctor Manises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PACKAGE CLASS TREE INDEX HELP

PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES

SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

graph2D

Class Graph2D

java.lang.Object
java.awt.event.WindowAdapter
graph2D.Graph2D
All Implemented Interfaces:
java.awt.event.WindowFocusListener, java.awt.event.WindowListener,
java.awt.event.WindowStateListener, java.util.EventListener
Direct Known Subclasses:
Plotter

public class Graph2D


extends java.awt.event.WindowAdapter

Graph2D let users work with a graphic space for drawing strings, points, lines, polylines, polygons,
arcs and filled arcs.
Version:
(1.2)
Author:
(CC-BY-NC-SA. IIP, PRG, EDA @ ETSINF-UPV. pmarques)

Field Summary

Fields

Modifier and Type Field and Description

static java.awt.Color BCK_C


Background Color (WHITE).

static java.awt.Font DEF_FONT


The, by default, Font for drawing Strings.

static int DEF_THICKNESS


The, by default, thickness of lines and points.

static java.awt.Color FOR_1


Foreground Color 1 (BLACK).

static java.awt.Color FOR_2


Foreground Color 2 (BLUE).

static int INI_HEIGHT


Initial graph height in pixels.

static int INI_WIDTH


Initial graph width in pixels.

Constructor Summary
Constructors

Constructor and Description

Graph2D()
The by default constructor creates a squared working space for x in [-1.0 .. +1.0] and y in [-1.0 ..
+1.0].

Graph2D(double mX, double xX, double mY, double xY)


Creates a Graph2D with real dimensions and default window dimensions, background color and
title.

Graph2D(double mX, double xX, double mY, double xY, int wWidth, int wHeight)


Creates a Graph2D with real and window dimensions, with default background color and title.

Graph2D(double mX, double xX, double mY, double xY, int wWidth, int wHeight,


java.awt.Color bckCol, java.lang.String t)
Creates a Graph2D with real dimensions, window dimensions, bckCol color and t title.

Method Summary

All Methods Instance Methods Concrete Methods

Modifier and Type Method and Description

void clear()
Clear all elements, reestablishing background color and, possibly, axes
and mouse position.

void drawArc(double x, double y, double w, double h, int sA,


int aA)
Draws an arc inclosed in a rectangular area given by the coordinate of
its upper left corner (x,y), its width w and height h.

void drawArc(double x, double y, double w, double h, int sA,


int aA, java.awt.Color c, int th)
Draws an arc inclosed in a rectangular area given by the coordinate of
its upper left corner (x,y), its width w and height h.

void drawLine(double x1, double y1, double x2, double y2)


Draws a line between (x1,y1) and (x2,y2).

void drawLine(double x1, double y1, double x2, double y2,


java.awt.Color c, int th)
Draws a line between (x1,y1) and (x2,y2) with Color c and th
thickness.

void drawOval(double x, double y, double w, double h)


Draws an oval inclosed in a rectangular area given by the coordinate of
its upper left corner (x,y), Color c and thickness th.

void drawOval(double x, double y, double w, double h,


java.awt.Color c, int th)
Draws an oval inclosed in a rectangular area given by the coordinate of
its upper left corner (x,y), Color c and thickness th.

void drawPoint(double x, double y)


Draws a point given its real (x,y) coordinates.

void drawPoint(double x, double y, java.awt.Color c, int th)


Draws a point with Color c and th thickness, given its real (x,y)
coordinates.

void drawPolyline(double[] xCoords, double[] yCoords)


Draws an open (not closed) polygonal line with points defined in the
arrays xCoords, and yCoords with same index.

void drawPolyline(double[] xCoords, double[] yCoords,


java.awt.Color c, int th)
Draws an open (not closed) polygonal line with points defined in the
arrays xCoords, and yCoords with same index.

void drawRect(double x, double y, double w, double h)


Draws a rectangle as given by the coordinate of its upper left corner
(x,y) and its width w and height h.

void drawRect(double x, double y, double w, double h,


java.awt.Color c, int th)
Draws a rectangle as given by the coordinate of its upper left corner
(x,y) and its width w and height h.

void drawString(double x, double y, java.awt.Color c,


java.lang.String s, java.awt.Font f)
Draws a String with the baseline of the leftmost character at position
(x, y), with Color c and Font f.

void drawString(double x, double y, java.lang.String s)


Draws a String with the baseline of the leftmost character at position
(x, y), with default Font and Color.

void fillArc(double x, double y, double w, double h, int sA,


int aA)
Paints a filled arc (coloured) inclosed in a rectangular area given by the
coordinate of its upper left corner (x,y), width w and height h.

void fillArc(double x, double y, double w, double h, int sA,


int aA, java.awt.Color c, int th)
Draws a filled arc (coloured) inclosed in a rectangular area given by the
coordinate of its upper left corner (x,y), width w and height h.

void fillOval(double x, double y, double w, double h)


Paints a coloured oval inclosed in a rectangular area given by the
coordinate of its upper left corner (x,y), with default thickness and
Color.

void fillOval(double x, double y, double w, double h,


java.awt.Color c, int th)
Paints (fills) a coloured oval inclosed in a rectangular area given by the
coordinate of its upper left corner (x,y), Color c and thickness th.

void fillPolygon(double[] xCoords, double[] yCoords)


Paints an closed (coloured filled) polygon with points defined in the
arrays xCoords, and yCoords with same index.

void fillPolygon(double[] xCoords, double[] yCoords,


java.awt.Color c, int th)
Paints an closed (coloured filled) polygon with points defined in the
arrays xCoords, and yCoords with same index.

void fillRect(double x, double y, double w, double h)


Paints (fills) a rectangle as given by the coordinate of its upper left
corner (x,y) and its width w and height h.
void fillRect(double x, double y, double w, double h,
java.awt.Color c, int th)
Paints (fills) a rectangle as given by the coordinate of its upper left
corner (x,y) and its width w and height h.

java.awt.Color getBackgroundColor()
Returns the current setting for the background color.

java.awt.Font getFont()
Returns the current setting for the Font.

java.awt.Color getForegroundColor()
Returns the current setting for the foreground color.

double getMaxX()
Returns the maximum x coordinate.

double getMaxY()
Returns the maximum y coordinate.

double getMinX()
Returns the minimum x coordinate.

double getMinY()
Returns the minimum y coordinate.

int getThickness()
Returns the current setting for the thickness of the elements.

void setBackgroundColor(java.awt.Color c)
Set background Color c, for drawing from now on.

void setFont(java.awt.Font f)
Set the Font f for drawing Strings from now on.

void setForegroundColor(java.awt.Color c)
Set foreground Color c, for drawing from now on.

void setGraphDimensions(double miX, double maX, double miY,


double maY)
Modify the real graph dimensions with a new x-interval [miX .. maX]
and a new y-interval [miY .. maY].

void setResizable(boolean sR)
Makes the Graphic window resizable or not.

void setThickness(int th)
Set lines and points thickness th for drawing from now on.

void setTitle(java.lang.String tit)
Sets the title of the graph window.

void setXRange(double miX, double maX)


Modify the real graph dimensions with a new x-interval [miX .. maX].

void setYRange(double miY, double maY)


Modify the real graph dimensions with a new y-interval [miY .. maY].

void showAxes(boolean opt)
Set drawing axes on (true by default) or off (false).

void showMousePosition(boolean opt)
Set showing mouse position on (true by default) or off (false).

You might also like