Note that there are some explanatory texts on larger screens.

plurals
  1. POmoving a shape across a jframe
    primarykey
    data
    text
    <p>Basically my entire program is to have shapes move across a JFrame, and the problem I am having is that I cannot get my object to move.</p> <p>I have a class called Creatures and the constructor creates my body and tail of my fish. (I'm making an aquarium). This class extends to another class that has a move() method, so that everytime a timer event happens the picture moves. </p> <p>Again my problem is that I cannot get the picture/shape/object to move. If anyone could lend a hand I would be most grateful =]</p> <p>Here is the full class of Creatures</p> <pre><code>import java.awt.geom.Ellipse2D; import java.awt.Color; import java.awt.Polygon; import java.awt.Graphics2D; public class Creatures extends Moveable2DShape{ private Color color; private int delay, number; private int xPos2, yPos2; private final int POINTS = 3; private int []x = new int[POINTS]; private int []y = new int[POINTS]; private double width, height; Ellipse2D.Double body; Polygon tail; public Creatures(int xPos, int yPos, int shapeWidth, int shapeHeight, int bwidth, int bheight, double xSpeed, double ySpeed, Color c){ super(xPos, yPos, shapeWidth, shapeHeight, bwidth, bheight, xSpeed, ySpeed); color = c; xPos2 = xPos; yPos2 = yPos; width = shapeWidth; height = shapeHeight; } public Polygon triangle(int xPos, int yPos){ x[0] = xPos + 100; x[1] = x[0]; x[2] = (int)(xPos + width/2); y[0] = (int)(yPos + (height)); y[1] = yPos; y[2] = (int)(yPos + height/2); tail = new Polygon(x,y,POINTS); return tail; } //public void move(){ } public void draw(Graphics2D g){ body = new Ellipse2D.Double(xPos2, yPos2, width, height); //System.out.println(xPos2 + " " + yPos2 + " " + width + " " + height); triangle(xPos2, yPos2); g.setColor(color); g.fill(body); g.fill(tail); } } </code></pre> <p>I'm supposed to override the move() method that is inherited from the Moveabled2DShape class but i havent yet because I just wanted to test out the method before overriding it. But now my problem is that I need to update xPos2 and yPos2</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload