2D shape problem

I

Ian Stanley

Hi again,
continuing my ongoing problem:
I am getting the following repeated error messages and am stuck with how to
fix them.
1)java.awt.geom.AffineTransform cannot be applied to shape
2)cannot resolve symbol: method getbounds()
I was originally implementing Shape but since switching to the inheritance
structure(would like to add several different types of shapes) below I have
got confused.
I am thinking that since no longer implementig Shape interface nad calling
my abstract class Shape I have "lost getbounds".
Is there a way around this.
Is it the way I have named my classes?
Any help apprecited
regards
Ian.

the idea is to can click on a panel and insert as shape to vector v passing
using
if (drawingMode == OVAL){
newShape = new Ellipse(x, y, circW, circH);
insertShape(newShape);
repaint();
}
private void insertShape(Shape newshape) {
v.addElement(newshape);
}
The X & Y coords are then passed to this method and the Shape is "Shrunk"
public Shape shrinkShape(int x, int y) {
for (int i = 0; i < v.size(); i++){
Shape s = (Shape)v.elementAt(i);
if (s.contains(x,y) ){
int anchorX = s.getBounds().x + s.getBounds().width/2;
int anchorY = s.getBounds().y + s.getBounds().height /2;
AffineTransform tr =
AffineTransform.getScaleInstance(0.7,0.7);
}
Shape ts = tr.createTransformedShape(current_shape);
int newX = ts.getBounds().x + ts.getBounds().width/2;
int newY = ts.getBounds().y + ts.getBounds().height/2;
tr =
AffineTransform. getTranslateInstance((anchorX - newX),
(anchorY - newY ) );
ts = tr.createTransformedShape(ts);
v.addElement(ts);
v.removeElement(s);
repaint();
}
}
return null;
}
My Shape and Ellipse classes:
abstract class Shape {
int x, y;
public abstract void draw(Graphics g);
}

class Ellipse extends Shape {
float a, b; // Semimajor and semiminor axes.
Ellipse(int left, int top, float semiMajorAxis, float semiMinorAxis){
x = left; y = top;
a = semiMajorAxis;
b = semiMinorAxis;
}
public void draw(Graphics g) {
g.fillOval(this.x, this.y, (int)(this.a), (int)(this.b));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top