ProjektGraph/visualizationElements/BarChartElement.java
2024-06-27 11:07:46 +02:00

77 lines
1.5 KiB
Java

package visualizationElements;
import java.awt.Color;
import java.awt.Graphics;
/**
* 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;
}
}