how is sizeof each arraylist object determined
in
Programming Questions
•
7 months ago
for some time now I have been using arraylist as a means to store data
but there is always some worry about getting the the size of the list too big,
so how is the size of each object determined especially when you are using your own custom class
is the class wrapped for each object or are the parameters passed to the constructor alone are saved when the new objects are created and when manipulating that object are the parameters again passed to the same class
the main reason I'm asking this is because after I got into processing I have started looking into java 2d Garphics
I made the class below to draw shapes I realize that I could just use the shape method already provided but I did not want to simply save the x,y,width,height alone but the fill and stroke color as well
you can actually see that the contains method is actually from the button example from processing
NOTE: I have not actually used string switch case before but that actually works
- class drawShape {
- private float x, y, width, height;
- Color fillcolor, strokecolor;
- String shapetype;
- Shape shape;
- public drawShape(String shapetype, float x, float y, float width, float height, Color fillcolor,Color strokecolor)
- {
- this.x =x;
- this.y = y;
- this.width=width;
- this.height=height;
- this.fillcolor= fillcolor;
- this.strokecolor= strokecolor;
- this.shapetype= shapetype;
- }
- public void draw(Graphics g) {
- Graphics2D g2 = (Graphics2D)g;
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- shapetype.toLowerCase();
- float x1 = Math.min(x, width);
- float y1 = Math.min(y, height);
- float width1 = Math.abs(x-width);
- float height1 = Math.abs(y- height);
- switch(shapetype)
- {
- case "rect":
- shape = new Rectangle2D.Float(x1,y1,width1,height1);
- break;
- case "ellipse":
- shape = new Ellipse2D.Float(x1,y1,width1,height1);
- break;
- case "line":
- shape = new Line2D.Float(x, y, width, height);
- break;
- default:
- System.out.println("No Shape Selected");
- break;
- }
- g2.setStroke(new BasicStroke(4));
- g2.setPaint(strokecolor);
- g2.draw(shape);
- g2.setPaint(fillcolor);
- g2.fill(shape);
- }
- boolean contains(float posx, float posy) {
- float diameter= (float) Math.PI*((width/2)*(height/2));
- float disX = x - posx;
- float disY = y - posy;
- if (Math.sqrt((disX*disX) + (disY*disY)) < diameter/2 ) {
- return true;
- } else {
- return false;
- }
- }
- }
EDIT: since I'm asking anyways let me ask on more thing
I have seen
- public void draw(Graphics g) {
- Graphics2D g2 = (Graphics2D)g;
sometimes it is cast to graphics2d object
I have also seen this
what exactly is the difference
- public void draw(Graphics2D g2) {
1