ProjektGraph/visualizationElements/BarChartElement.java

76 lines
1.4 KiB
Java
Raw Permalink Normal View History

package visualizationElements;
2024-07-02 19:13:30 +00:00
import java.awt.*;
/**
* Represents a bar within a bar chart.
* @author MSchaefer
*
*/
public class BarChartElement {
private Color color;
private int value;
/**
* Creates a new BarChartElement.
* @param value Value (size) of the bar.
* @param color Coloring of the bar.
*/
public BarChartElement(int value, Color color){
this.setValue(value);
this.setColor(color);
}
/**
* Creates a new BarChartElement.
* @param value Value (size) of the bar.
*/
public BarChartElement(int value){
this.setValue(value);
this.setColor(Color.BLACK);
}
/**
* Draws the BarChartElement
* @param g The Graphics object to draw the element to the DrawArea.
* @param xpos Horizontal position where the barChartElement is drawn.
* @param yPos Vertical position where the barChartElement is drawn.
* @param width Width of the barChartElement.
* @param height Height of the barChartElement.
*/
public void draw(Graphics g, int xpos, int yPos, int width, int height) {
g.setColor(this.getColor());
g.fillRect(xpos, yPos, width, height);
}
/**
* @param value the value to set
*/
public void setValue(int value) {
this.value = value;
}
/**
* @return the value
*/
public int getValue() {
return value;
}
/**
* @param color the color to set
*/
public void setColor(Color color) {
this.color = color;
}
/**
* @return the color
*/
public Color getColor() {
return color;
}
}